I am trying to write some reg expression validation on a PHP form, and I have the following:
/^([+]{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.
/^([+][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 +
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.