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.