【发布时间】:2018-07-03 05:25:31
【问题描述】:
我有一个form validator by AntonLapshin,我正在尝试验证一个非空输入字段,该字段只能使用字母、空格和 - 和'。字母可以是 a-z、A-Z 和欧式字母 æÆøØåÅöÖéÉèÈüÜ 等。See this for more details。
这是我正在做的事情:
method : function(input) {
return input.value !== ''
&& input.value === /^[a-zA-Z'\- \u00c0-\u017e]+$/
}
这里应该匹配:Åløæ-Bond Mc'Cool
但失败:123-Bond Mc'C@o!
当我在regex tester 中运行^[a-zA-Z'\- \u00c0-\u017e]+$ 时,它工作得非常好,但在我的脚本中,它没有进行验证并引发无效输入错误。
我做错了什么?
【问题讨论】:
-
从你的脚本中得到错误会很有帮助
-
你的脚本有什么错误?
-
我的脚本中没有语法错误。这只是正则表达式模式不起作用。
标签: javascript regex validation