Regular expression not working for at least one European character

I am checking whether my string contains at least one character of a European language(Example: German, Spanish,English etc...)

I tried like the following:

var check = "abc";

if(check.match(/^[a-zA-ZäöåÄÖÅ]+$/)){
               alert("if");
               }
   else{
   alert("else");
   }

It should only work if it is having at least a European language character. Should not work if numbers only. Please guide me guys!!

Answers:

Answer

You just need to remove the anchors and the quantifier and use test:

alert(/(?![×÷])[A-Za-zÀ-ÿ]/.test("ß1111"))
alert(/(?![×÷])[A-Za-zÀ-ÿ]/.test("ö"))
alert(/(?![×÷])[A-Za-zÀ-ÿ]/.test("12345"))

The (?![×÷])[A-Za-zÀ-ÿ] regex is an adaptation of the regex provided in Useful ASCII Ranges. It will capture all Latin and accented characters.

Some more language-related character ranges you can use:

French Letters: [a-zA-ZàâäôéèëêïîçùûüÿæœÀÂÄÔÉÈËÊÏΟÇÙÛÜÆŒ]

German Letters: [a-zA-ZäöüßÄÖÜ]

Polish Letters only: [a-pr-uwy-zA-PR-UWY-Z?????ó????????Ó???] (Note that there is no Q, V and X in Polish, but if you want to allow all English letters as well, use [a-zA-Z?????ó????????Ó???])

Italian Letters: [a-zA-ZàèéìíîòóùúÀÈÉÌÍÎÒÓÙÚ]

Spanish Letters: [a-zA-ZáéíñóúüÁÉÍÑÓÚÜ]

And some more...

Swedish: [a-zA-ZäöåÄÖÅ] (link)

Norwegian: [a-zA-ZæøåÆØÅ] (link)

Danish (same as Norwegian): [a-zA-ZæøåÆØÅ] (link)

Greek & Coptic + Greek Extended: [\u0370-\u03FF\u1F00-\u1FFF] (link)

Russian: [?-??-???] (link)

Ukrainian: [?-??-???????????????] (link)

Serbian (Cyrillic): [?-??-???-???-??-???-??] (link)

Bulgarian (subset of Russian alphabet): [?-?????-????] (link)

Belarusian script range: [??-??-??-???-??-??????] (link)

Romanian: [a-zA-Z?ÂÎ???âî??] (link)

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.