Cell phone number format regular expression
Match domestic phone number: D{3}-d{8}¦d{4}-d{7}
Commentary: Match form such as 0511-4405222 or 021-87888822
The front-end code I use Jquery.validate.js, the code is as follows:
JavaScript code
<script type= "Text/css Tutorial" >
$ (document). Ready (function () {
$ ("#smForm"). Validate ({
Rules: {
Smmobilephone: {
Required:true,
Digits:true,
RANGE:[13000000000,18999999999]
}
},
Messages: {
Smmobilephone: {
Required: "You did not fill in the mobile phone number",
Digits: "Phone number format is not correct",
Range: "Cell phone number length or wrong format",
}
},
Preerrs: {
}
});
});
</script>
This is only an inexact verification, can only be verified to a range, so the focus is still behind.
PHP code
$mobilephone =trim ($_post["Smmobilephone"]);
Regular verification of mobile phone number
if (Preg_match ("/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/", $mobilephone)) {
Validation through
}else{
Phone number is not in the right format
}
See examples
<?php Tutorial
Regular expressions
$tel = "15551530459";//The author's mobile number, if you have any questions, you can contact me by telephone, my mailbox is admin@www.3ppt.com
if (strlen ($tel) = = "11")
{
The above section determines whether the length is 11 bits
$n = Preg_match_all ("/13[123569]{1}d{8}|15[1235689]d{8}|188d{8}/", $tel, $array);
/* The next regular expression ("/131,132,133,135,136,139 followed by any 8 for the number ' | ') (or meaning)
* 151,152,153,156,158.159 at the beginning followed by any number 8
* or the beginning of the 188 followed by any of the 8 numbers, matching any of these groups passed the
* /")*/
Var_dump ($array); See if it's found, and if it does, it'll output the phone number.
}else
{
echo "Length must be 11 bits";
}
/*
* Although it looks complex, clear understanding!
* If there is a better, you can post it, share happiness!
* */
?>
Other reference
Matching Tencent QQ Number: [1-9][0-9]{4,}
Commentary: Tencent QQ number starting from 10000
Match China ZIP Code: [1-9]d{5} (?! D
Commentary: China postal code is 6 digits
Matching ID: d{15}¦d{18}
Commentary: China's ID card is 15-or 18-digit
Matching IP address: d+.d+.d+.d+
Commentary: Useful when extracting IP addresses
Match a specific number:
^[1-9]d*$//Matching positive integer
^-[1-9]d*$//matching negative integers
^-? [1-9]d*$//matching integer
^[1-9]d*¦0$//matching nonnegative integer (positive integer + 0)
^-[1-9]d*¦0$//matching non positive integer (negative integer + 0)
^[1-9]d*.d*¦0.d*[1-9]d*$//matching positive floating-point numbers
^-([1-9]d*.d*¦0.d*[1-9]d*) $//matching negative floating-point number
^-? ([1-9]d*.d*¦0.d*[1-9]d*¦0?. 0+¦0) $//matching floating-point number
^[1-9]d*.d*¦0.d*[1-9]d*¦0? 0+¦0$//matching nonnegative floating-point number (positive floating-point number + 0)
^ (-([1-9]d*.d*¦0.d*[1-9]d*)) ¦0? 0+¦0$//matching non-positive floating-point numbers (negative floating-point number + 0)
Commentary: useful when dealing with large amounts of data, pay attention to corrections when applied
Match a specific string:
^[a-za-z]+$//Match a string of 26 English letters
^[a-z]+$//Match a string of 26 uppercase letters
^[a-z]+$//Match string consisting of 26 lowercase letters
^[a-za-z0-9]+$//Match a string of numbers and 26 English letters
^w+$//Match A string of numbers, 26 English letters, or underscores
Commentary: Some of the most basic and commonly used expressions