Regular expressions for mobile phone number validation in PHP _php tutorial

Source: Internet
Author: User
The collection of two mobile phone number verification code, one is the front desk with jquery verification and then use the background PHP Tutorial code to verify the phone number is legitimate, I hope it is useful to everyone.
Front-end code I use Jquery.validate.js, the code is as follows:

JavaScript code

This is just an imprecise validation, and can only be verified to a range, so the focus is still behind.

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)) {
Validation by

}else{
Cell phone number format is incorrect

}

See Example

Regular expressions
$tel = "15558530459";//The author's mobile phone number, if there is doubt can contact me by phone, or QQ contact me, my QQ is mezongzi@qq.com
if (strlen ($tel) = = "11")
{
The upper part of the judging length is not 11 bit
$n = Preg_match_all ("/13[123569]{1}d{8}|15[1235689]d{8}|188d{8}/", $tel, $array);
/* Next Regular expression ("/131,132,133,135,136,139 begins followed by any 8 as number ' | ' (or meaning)
* 151,152,153,156,158.159 the beginning of the following arbitrary 8 for the number
* or a 188 start followed by any number of 8, matching any one of the groups passed
* /")*/

Var_dump ($array); See if it's found, and if it does, it will output the phone number.
}else
{
echo "Length must be 11 bits";
}
/*
* Although it looks more complicated, clear understanding!
* If there is better, can be posted out, share happiness!
* */
?>

http://www.bkjia.com/PHPjc/631333.html www.bkjia.com true http://www.bkjia.com/PHPjc/631333.html techarticle The collection of two mobile phone number verification code, one is the front desk with jquery verification and then use the background PHP Tutorial code to verify the phone number is legitimate, I hope it is useful to everyone. Front-end code I use JQ ...

  • 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.