PHP Validation Class Code

Source: Internet
Author: User
Tags php form
For a strict web development process, any form submission action must undergo rigorous format verification, not only the client to do the JS verification, server-side use of the program two verification is essential.

Here is a class for validating the format validation of a server-side form field in PHP format.

The specific code is as follows:

/*
* author:www.scutephp.com
* Time:2012-3-31 17:35:42
* function:php form field format validation
*/
Class verification{
Verifies that the string length is within the specified range [this verifies only the characters entered in the half-width State]
function Fun_length ($str, $min, $max) {
Return (strlen ($STR) > $max | | Strlen ($STR) < $min) False:true;
}
Verifies whether a combination of letters/numbers of a specified length
function Fun_text1 ($num 1, $num 2, $str) {
Return (Preg_match ("/^[a-za-z0-9]{". $num 1. ",". $num 2. "} $/", $str))? True:false;
}
Verifies whether a number is a specified length
function Fun_text2 ($num 1, $num 2, $str) {
Return (Preg_match ("/^[0-9]{". $num 1. ",". $num 2. "} $/i ", $str))? True:false;
}
Verifies whether the specified length is a Chinese character
function Fun_font ($num 1, $num 2, $str) {
Return (Preg_match ("/^ ([\x81-\xfe][\x40-\xfe]) {". $num 1. ",". $num 2. "} $/", $str))? True:false;
}
Verify email address
function Fun_email ($STR) {
Return (Preg_match ('/^[_\.0-9a-z-]+@ ([0-9a-z][0-9a-z-]+\.) +[a-z]{2,4}$/', $str))? True:false;
}
Verify phone number
function Fun_phone ($STR) {
Return (Preg_match ("/^1[358][0123456789]\d{8}$/", $str)) True:false;
}
Verify your phone number
function Fun_mobile ($STR) {
Return (Preg_match ("/^ ((D{3}) | ( d{3}-))? ((0d{2,3}) |0d{2,3}-)? [1-9]d{6,7}$/", $str))? True:false;
}
Verify ZIP Code
function Fun_zip ($STR) {
Return (Preg_match ("/^[1-9]d{5}$/", $str)) True:false;
}

}

The use of the above class is no longer illustrated here.

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