if (!preg_match('[/^1[3|5|7|8][0-9]\d{8}$/', $phone)){ return "PleaseEnterYourPhoneNumber";}
Both front and rear stations are/^1[3|5|7|8d{8}$/regular
Front desk verification used
Background execution return
Some people say that their web-based PHP regular library and JS are not the same
Is there any way to solve this?
Reply content:
if (!preg_match('[/^1[3|5|7|8][0-9]\d{8}$/', $phone)){ return "PleaseEnterYourPhoneNumber";}
Both front and rear stations are/^1[3|5|7|8d{8}$/regular
Front desk verification used
Background execution return
Some people say that their web-based PHP regular library and JS are not the same
Is there any way to solve this?
Can't bear it ...
Online This kind of regular is really is copied to copy, a write has a problem on all have problems, why refused to see the regular expression
[0-9]And \d is exactly equivalent ah, why to separate into [0-9]\d{8} , directly write a \d{9} not good
So just change /^1[3|5|7|8]\d{9}$/ it!
(The first one in your code [ must be copied or mistakenly typed)
As for your question, refer to the following two-paragraph code, which is completely equivalent in effect:
Php:
$re = '/^1[3|5|7|8]\d{9}$/'; $str = '13012345678'; if (preg_match($re, $str)) { echo '验证通过';} else { echo '验证失败';}
Javascript:
var re = /^1[3|5|7|8]\d{9}$/; var str = '13012345678';if (re.test(str)) { console.log('验证通过');} else { console.log('验证失败');}
//假设前台有个表单的name是phone$phone=$_POST['phone']; if ($phone != '[/^1[3|5|7|8][0-9]\d{8}$/'){ return "PleaseEnterYourPhoneNumber";}