简体   繁体   English

瑞典人用javascript检查?

[英]swedish characters check with javascript?

How can I rewrite this code to check for all characters including the swedish å, ä, and ö characters? 如何重写此代码以检查包括瑞典语,ä和ö字符在内的所有字符?

      alphaExp = /^[a-zA-Z]+$/;

The above only checks against english letters! 以上只检查英文字母!

The swedish contains å, ä, ö coming after the Z... rest is all the same as english. 瑞典人包含å,ä,ö在Z之后......休息与英语完全相同。

Thanks 谢谢

Did you try /^[a-zA-ZäöåÄÖÅ]+$/ ? 你试过/^[a-zA-ZäöåÄÖÅ]+$/

In my Firefox, /^[a-zA-ZäöåÄÖÅ]+$/.test("öÅ"); 在我的Firefox中,/ /^[a-zA-ZäöåÄÖÅ]+$/.test("öÅ"); evaluates to true. 评估为真。

Pretty much straight from the horse's mouth : 几乎直接来自马的嘴

Support for internationalization in JavaScript's RegExp is virtually nonexistent. 支持JavaScript的RegExp国际化几乎不存在。

See the posts following the linked one for how to get around this (by defining your own character class). 请参阅链接后的帖子,了解如何解决此问题(通过定义自己的角色类)。

You have PHP and JavaScript marked in here. 你在这里标记了PHP和JavaScript。 For the JavaScript answer, see the previous answer from Matt Ball. 有关JavaScript的答案,请参阅Matt Ball的上一个答案。

For the PHP answer, see \\p and friends. 有关PHP的答案,请参阅\\p和朋友。 \\p{L} for example. \\p{L}例如。

php -r '$foo = "täst"; if ( preg_match("/^\\p{L}+$/",$foo) ) echo "yay\n";'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM