Regular Expressions Used for Form Verification in php

Source: Internet
Author: User



Function is_email ($ str ){
// Check email
Return preg_match ("/^ \ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\. \ w + ([-.] \ w +) * $/", $ str );
}

Function is_url ($ str ){
// Check the website
Return preg_match ("/^ http: \ // [A-Za-z0-9] + \. [A-Za-z0-9] + [\/= \? % \-&_~ '@ [\] \': +!] * ([^ <> \ "])

* $/", $ Str );
}

Function is_qq ($ str ){

// Test qq
Return preg_match ("/^ [1-9] \ d {4, 8} $/", $ str );
}

Function is_zip ($ str ){

// Inspection zip code
Return preg_match ("/^ [1-9] \ d {5} $/", $ str );
}

Function is_idcard ($ str ){

// Check your ID card
Return preg_match ("/^ \ d {15} (\ d {2} [A-Za-z0-9])? $/", $ Str );
}

Function is_chinese ($ str ){

Check whether it is Chinese
Return ereg ("^ [". chr (0xa1). "-". chr (0xff). "] + $", $ str );
}

Function is_english ($ str ){

// Check whether it is in English
Return preg_match ("/^ [A-Za-z] + $/", $ str );
}

Function is_mobile ($ str ){

// Check whether it is a mobile phone
Return preg_match ("/^ (\ d {3} \) | (\ d {3 }\-))? 13 \ d {9 }$/", $ str );
}

Function is_phone ($ str ){

// Whether the phone number is used for cloud Creation
Return preg_match ("/^ (\ d {3} \) | (\ d {3 }\-))? (\ (0 \ d {2, 3} \) | 0 \ d {2, 3 }-)? [1-9] \ d {6, 7} $ /",

$ Str );
}

Function is_safe ($ str ){
Return (preg_match ("/^ ([A-Z] * | [a-z] * | \ d * | [-_\~! @ # \ $ % \ ^ & \ * \. \ (\) \ [\] \ {\} <> \? \/\ '\ "] *) |.

{0, 5}) $ | \ s/", $ str )! = 0 );
}
}

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.