jQuery validate插件:仅接受德语字母 [英] jQuery validate plugin: accept only German letters
问题描述
我正在寻找一种用于jquery validate插件的方法( http://bassistance .de/jquery-plugins/jquery-plugin-validation/),仅接受字母,包括德语中所谓的Umlaute(öäüÖÄÜß).我对正则表达式不好,所以我写自己的规则失败了. 你有什么主意吗?任何帮助表示赞赏!提前谢谢! :)
I am looking for a method for the jquery validate plugin (http://bassistance.de/jquery-plugins/jquery-plugin-validation/), that only accepts letters, including the German so called Umlaute (öäüÖÄÜß).. I googled a bit, but unfortunately couldn't find anything. I'm not good with regex, so I failed writing my own rule.. Do you have any idea? Any help is appreciated! Thx in advance! :)
到目前为止,这是我的方法:
Here is my method so far:
jQuery.validator.addMethod("lettersonly", function(value, element) {
return this.optional(element) || /^[a-zA-ZüöäÜÖÄß]+$/i.test(value);
}, "Letters only please");
解决方案:该方法有效!问题在于,将元标记"content-type"设置为ISO错误,但是当然必须为UTF-8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
SOLUTION: The method works! The problem was that the meta tag "content-type" was set wrong to ISO, but it has to be UTF-8 of course. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
推荐答案
[a-zA-Z\u0196\u0228\u0214\u0246\u0220\u0252\u0223]
这些是德语字母(包括普通字母)的unicode字符.
These are the unicode characters for german letters, including the normal letters.
这是正常现象:
[a-zA-ZüöäÜÖÄß]
这取决于您输入的内容.
It depends on what your input is.
以上匹配单个字母.由于您没有提供示例输入,因此我们无法使正则表达式规则更加具体!
The above matches single letters. Since you provide no sample input we can't make the regex rule more specific!
这篇关于jQuery validate插件:仅接受德语字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!