Regular Expression for mobile phone number verification in php

Source: Internet
Author: User

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!
**/
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.