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!!
Solution 1:
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)