Various regular expressions are listed

Source: Internet
Author: User

Verifying the regular user name
$user _name = ' user_name12 ';
if (Preg_match ('/^[a-z\d_]{5,20}$/i ', $user _name)) {
Echo ' Your username is ok '. Php_eol. ' <br> ';
} else {
Echo ' Your username is error ';
}
Verify the date's regular
$date = Date (' y-m-d ');
if (Preg_match ('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/i ', $date)) {
Echo ' date is ok '. Php_eol. ' <br> ';
} else {
Echo ' date is error ';
}
Verify postal code
$zipcode = "12354-5432";
if (Preg_match ('/^ ([0-9]{5}) (-[0-9]{4})? $/i ', $zipcode)) {
Echo ' ZipCode is ok '. Php_eol. ' <br> ';
} else {
Echo ' ZipCode is error ';
}
Mobile phone number Verification
$tel = "15043947153";
if (Preg_match ('/^0? ( 13[0-9]|15[012356789]|17[0123456789]|18[0-9]|14[0-9]) [0-9]{8}$/i ', $tel)) {
Echo ' Tel is ok '. Php_eol. ' <br> ';
} else {
Echo ' Tel is error ';
}
Mailbox Verification
$email = "[email protected]";
if (Preg_match ("/^[0-9a-za-z][email protected" ([0-9a-za-z]+) [.]) +[a-z]{2,4}$/i ", $email)) {
Echo ' Email is ok '. Php_eol. ' <br> ';
} else {
echo ' Email IE error ';
}

Various regular expressions are listed

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.