[英]PHP Regular expression is validating, but the javascript is not
I am trying to write some reg expression validation on a PHP form, and I have the following: 我正在尝试在PHP表单上编写一些reg表达式验证,并且我具有以下内容:
/^([+]{1}[0-9]{1,2}[\s]?[0-9]{1,10}[\s][0-9]{1-6}?)|([+][0-9]{1,2}[\s]?[0-9]{1,4}[\s]?[0-9]{1,6})|([+]?[0-9]{2,3}?[\s]?[0-9]{1,3}[\s])?([0-9]{1,5})?[0-9]{3}[\s]?[0-9]{5,6}$/i
but the javascript version shown below is claiming it not to be valid, even though I can successfully submit the form showing that the PHP version will accept the expression. 但是,即使我可以成功提交显示PHP版本将接受该表达式的表格,但下面显示的javascript版本也声称它无效。
/^([+][0-9]{1,2}[\\s]?[0-9]{1,10}[\\s][0-9]{1-6}?)|([+][0-9]{1,2}[\\s]?[0-9]{1,4}[\\s]?[0-9]{1,6})|([+]?[0-9]{2,3}?[\\s]?[0-9]{1,3}[\\s])?([0-9]{1,5})?[0-9]{3}[\\s]?[0-9]{5,6}$/i
Thanks in advance for your help. 在此先感谢您的帮助。
Because you're trying to escape \\
by \\\\
, which is not needed 因为你想逃跑
\\
由\\\\
,这是没有必要
And you should escape +
by \\+
if you are trying to match the literal +
你应该逃脱
+
由\\+
如果你试图匹配字面+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.