问题描述
我正在检查我的字符串是否包含至少一个欧洲语言的字符(例如:德语,西班牙语,英语等...)
我试过像以下:
var check =abc;
if(check.match(/ ^ [a-zA-ZäöåÄÅ] + $ /)){
alert(if);
}
else {
alert(else);
}
它应该只在至少具有欧洲语言字符时才有效。如果只是数字,不应该工作。请指导我们!!
您只需删除锚点和量词并使用测试
:
alert(/(?![ ×÷])[A-ZA-ZA-Y] /。测试( ß1111))警报(/(?![×÷])[A-ZA-ZA-Y] /。试验( O) )警报(/(?![×÷])[A-ZA-ZA-Y] /。试验( 12345))
(?![×÷])[A-Za-zÀ-ÿ]
正则表达式是修改了中提供的正则表达式。它将捕获所有拉丁和重音字符。
更多:
法语字母: [a-zA-ZàâäôéèëêïîçùûüÿæœÀÂÄÔÉÈËÊÏΟÇÙÛÜÆŒ]
德语来信: [ a-zA-ZäöüßÄÖÜ]
波兰语仅限信件: [a-pr- uwy-zA-PR-UWY-ZąćęłńóśźżĄĆĘŁŃÓŚŹŻ]
(注意没有 Q
,和 X
,但如果您还想允许所有英文字母,请使用 [a-zA -ZąćęłńóśźżĄĆĘŁŃÓŚŹŻ]
)
意大利语来信: [a-zA-ZàèéìíîòóùúÀÈÉÌÍÎÒÓÙÚ]
西班牙语信件: [a-zA-Záéí ñóúüÁÉÍÑÓÚÜ]
还有一些......
瑞典语: [a-zA-ZäöåÄÖÅ]
()
挪威语: [a-zA-ZæøåÆØÅ]
()
希腊语&科普特+希腊语扩展: [\ u0370-\ u03FF \ u1F00-\ u1FFF]
()
俄语: [а-яА-ЯёЁ]
()
乌克兰语: [а-щА-ЩЬьЮюЯяЇїІіЄєҐґ]
()
塞尔维亚语(西里尔语): [А-ИК-ШЂЈ-ЋЏа-ик-шђј-ћџ]
()
保加利亚语(俄语字母的子集): [ а-ъьюяА-ЪЬЮЯ]
()
Be larusian 脚本范围: [ёа-зй-шы-яЁА-ЗЙ-ШЫІіЎў]
()
罗马尼亚语: [a- zA-ZĂÂÎŞŢăâîşţ]
()
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!!
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)
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)
这篇关于正则表达式不适用于至少一个欧洲角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!