First use /^[0-9]*$/ to determine whether it is a pure number. If it is, enter the logic of mobile phone number verification. Use /^1[3|4|5|7|8]d{9}$ / to verify whether it is a legal mobile phone number.
If it is not a pure number, enter the logic of email verification. /^w+((-w+)|(.w+))@[A-Za-z0-9]+((.|-)[A-Za- z0-9]+).[A-Za-z0-9]+$/ can be used to verify email
Use this to verify the email address, and then when it returns false, use the regular pattern to verify the mobile phone number, like this. $email = 'fengdingbo@gmail.com'; $result = filter_var($email, FILTER_VALIDATE_EMAIL); var_dump($result); // string(20) "fengdingbo@gmail.com"
First use /^[0-9]*$/ to determine whether it is a pure number. If it is, enter the logic of mobile phone number verification. Use /^1[3|4|5|7|8]d{9}$ / to verify whether it is a legal mobile phone number.
If it is not a pure number, enter the logic of email verification. /^w+((-w+)|(.w+))@[A-Za-z0-9]+((.|-)[A-Za- z0-9]+).[A-Za-z0-9]+$/ can be used to verify email
Use this to verify the email address, and then when it returns false, use the regular pattern to verify the mobile phone number, like this.
$email = 'fengdingbo@gmail.com';
$result = filter_var($email, FILTER_VALIDATE_EMAIL);
var_dump($result); // string(20) "fengdingbo@gmail.com"
It’s a bit loose to verify email and mobile phone number at the same time. You can take a look at the example below