验证输入字段,其中站点使用德语和英语
我对验证字段(例如公司名称、公司名称、地址等)的问题感到非常困惑,因为该网站具有本地化功能。目前,我正在通过正则表达式(我的正则表达式之一的片段)使用 jQuery 验证字段:
var regex = /^[a-zA-Z0-9-,.\säöüÄÖÜ]{2,}$/;
当网站使用英语时,这可以正常工作。但是,我不确定这是否在德国环境中有效。
我测试验证的方法是在 Windows 上使用字符映射表。举例来说,我从字符映射表中得到ü,将其粘贴到字段上。但脚本说这是一个无效字符。然而,如果您查看正则表达式,我认为此类字符是有效的。
I am quite confused on the issue of validating the fields (eg. business name, company name, address, etc.), because the site has localization feature. Currently, I am validating the fields using jQuery via regular expression, a snip of one of my regex:
var regex = /^[a-zA-Z0-9-,.\säöüÄÖÜ]{2,}$/;
This works fine when the site is in English language. However, I am not confident if this does work in German environment.
What I do to test my validation is by using Character Map on Windows. Say for example, I get ü from Character Map, paste it on the field. But the script says it is an invalid character. Whereas, if you look on the regex, I am considering such character as valid.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最有可能的技术问题在于文档的字符编码。确保您的文档采用 UTF-8 编码,并在 HTTP 标头中或至少在
meta
标记中进行声明。但还有更困难的重要问题。例如,您的正则表达式将拒绝英语名称 Brontë 和德语名称 Strauß。它会接受 42,这几乎不是任何人的名字或姓氏。
这项检查的目的是什么?你能期望所有的名字都是英文或德文吗?根据欧洲惯例,一个人有权在欧洲国家正确拼写自己的名字,即使它碰巧使用的语言不是主要语言。
没有太多的个人姓名检查可以避免在某些公认的拼写中拒绝某人的真实姓名的风险。如果您需要将名称强制为某些有限的字符库或语法,则需要向用户明确这一点并在服务器端执行,最好还作为客户端预检查。
Most probably the technical problem is in the document’s character encoding. Make sure that your document is UTF-8 encoded and declared as such in HTTP headers or at least in a
meta
tag.There are more difficult important problems though. Your regexp will reject the English name Brontë and the German name Strauß for example. And it will accept 42, which is hardly anyone’s first or last name.
What is the purpose of this checking? Can you expect that all the names will be English or German? According to European conventions, a person has the right to have his name spelled correctly in European countries, even if it happens to be in a language other than the majority language.
There’s not much checking of personal names that you can do without risk of rejecting someone’s real name in some accepted spelling. If you need to force names to some limited character repertoire or syntax, this needs to be made clear to users and performed server-side and, preferably, additionally as client-side pre-checking.