Two cell phone number verification codes are added to the favorites. First, the front-end uses jquery to verify the validity of the mobile phone number with the background php tutorial code.
I use jquery. validate. js as the front-end Code. The Code is as follows:
JavaScript code
<Script type = "text/Webpage effects">
$ (Document). ready (function (){
$ ("# SmForm"). validate ({
Rules :{
SmMobilePhone :{
Required: true,
Digits: true,
Range: [13000000000,18999999999]
}
},
Messages :{
SmMobilePhone :{
Required: "You have not entered the mobile phone number ",
Digits: "the mobile phone number format is incorrect ",
Range: "The phone number length or format is incorrect ",
}
},
PreErrs :{
}
});
});
</Script>
This is just an inaccurate verification, and it can only be roughly verified to a specific range, so the focus is still on the future.
PHP code
$ Mobilephone = trim ($ _ POST ["smMobilePhone"]);
// Regular verification of mobile phone numbers
If (preg_match ("/^ 13 [0-9] {1} [0-9] {8} $ | 15 [0189] {1} [0-9] {8} $ | 189 [0-9] {8} $ /", $ mobilephone )){
// Verification passed
} Else {
// Incorrect Mobile Phone Number Format
}
View instances
<? Php
// Regular Expression
$ Tel = "15558530459"; // The author's mobile phone number, if you have any questions can contact me by phone, or QQ contact me, My QQ is mezongzi@qq.com
If (strlen ($ tel) = "11 ")
{
// The above part determines whether the length is 11 characters long
$ N = preg_match_all ("/13 [123569] {1} d {8} | 15 [1235689] d {8} | 188d {8}/", $ tel, $ array );
/* The subsequent regular expression ("/131,132,133,135,136,139 starts with any 8 followed by a number '|' (OR)
* Any 8 digits starting with 151,152,153,156,158.159
* If the number starts with 188 and then any 8 is a number, matching any group of numbers will pass.
*/")*/
Var_dump ($ array); // check whether it is found. If it is found, the phone number is output.
} Else
{
Echo "the length must be 11 characters ";
}
/*
* Although it looks complicated, it's easy to understand!
* If it is better, you can post it and share your happiness!
**/
?>