Common regular expression collation for PHP forms

Source: Internet
Author: User

function Is_email ($STR) {
Check Email
Return Preg_match ("/^\w+" ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$/", $str);
}

function Is_url ($STR) {
Inspection website
Return Preg_match ("/^http:\/\/[a-za-z0-9]+\.[ a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!] * ([^<>\])

*$/", $STR);
}

function Is_qq ($STR) {

Check 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) {

Inspection ID
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) {

Test whether it is in English
Return Preg_match ("/^[a-za-z]+$/", $str);
}

function Is_mobile ($STR) {

Check if it's a cell phone
Return Preg_match ("/^ (\ (\d{3}\)) | ( \d{3}\-)) 13\d{9}$/", $str);
}

function Is_phone ($STR) {

BYOC, is that the phone?
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*| [-_\[email protected]#\$%\^&\*\.\ (\) \[\]\{\}<>\?\\\/\ ' \ "]*) |.

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

Common regular expression collation for PHP forms

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.