Common form verification classes. with this, General verification is complete .. Copy the code as follows :? Php *** page function: Common form verification classes * author: Happy With The Wind * creation Time: 2006-3-6 * QQ: 276624915 * classclass_post {verify whether it is specified
The code is as follows:
/**
* Page function: Common form verification classes
* Author: happy with the wind
* Creation Time: 2006-3-6
* QQ: 276624915
*/
Class class_post
{
// Verify whether it is a combination of letters and numbers with a specified length
Function fun_text1 ($ num1, $ num2, $ str)
{
Return (preg_match ("/^ [a-zA-Z0-9] {". $ num1. ",". $ num2. "} $/", $ str ))? True: false;
}
// Verify whether it is a number of the specified length
Function fun_text2 ($ num1, $ num2, $ str)
{
Return (preg_match ("/^ [0-9] {". $ num1. ",". $ num2. "} $/I", $ str ))? True: false;
}
// Verify whether the Chinese character is of the specified length
Function fun_font ($ num1, $ num2, $ str)
{
// Preg_match ("/^ [\ xa0-\ xff] {1, 4} $/", $ string );
Return (preg_match ("/^ ([\ x81-\ xfe] [\ x40-\ xfe]) {". $ num1 .",". $ num2. "} $/", $ str ))? True: false;
}
// Verify the ID card number
Function fun_status ($ str)
{
Return (preg_match ('/(^ ([\ d] {15} | [\ d] {18} | [\ d] {17} x) $ )/', $ str ))? True: false;
}
// Verify the 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 the phone number
Function fun_phone ($ str)
{
Return (preg_match ("/^ (\ d {3} \) | (\ d {3 }\-))? (\ (0 \ d {2, 3} \) | 0 \ d {2, 3 }-)? [1-9] \ d {6, 7} $/", $ str ))? True: false;
}
// Verify the ZIP code
Function fun_zip ($ str)
{
Return (preg_match ("/^ [1-9] \ d {5} $/", $ str ))? True: false;
}
// Verify the url
Function fun_url ($ str)
{
Return (preg_match ("/^ http: \ // [A-Za-z0-9] + \. [A-Za-z0-9] + [\/= \? % \-&_~ '@ [\] \': +!] * ([^ <> \ "\"]) * $/", $ Str ))? True: false;
}
// The data warehouse receiving escape special character input value can be a string or a one-dimensional array
Function data_join (& $ data)
{
If (get_magic_quotes_gpc () = false)
{
If (is_array ($ data ))
{
Foreach ($ data as $ k => $ v)
{
$ Data [$ k] = addslashes ($ v );
}
}
Else
{
$ Data = addslashes ($ data );
}
}
Return $ data;
}
// Data warehouse restore special character input value can be a string or one/two-dimensional array
Function data_revert (& $ data)
{
If (is_array ($ data ))
{
Foreach ($ data as $ k1 => $ v1)
{
If (is_array ($ v1 ))
{
Foreach ($ v1 as $ k2 => $ v2)
{
$ Data [$ k1] [$ k2] = stripslashes ($ v2 );
}
}
Else
{
$ Data [$ k1] = stripslashes ($ v1 );
}
}
}
Else
{
$ Data = stripslashes ($ data );
}
Return $ data;
}
// The Data Display restoration data format is mainly used for the input value of the content output to be a string or a/two-dimensional array.
// Data_revert () should be performed before this method is executed, and the form content does not need to be restored
Function data_show (& $ data)
{
If (is_array ($ data ))
{
Foreach ($ data as $ k1 => $ v1)
{
If (is_array ($ v1 ))
{
Foreach ($ v1 as $ k2 => $ v2)
{
$ Data [$ k1] [$ k2] = nl2br (htmlspecialchars ($ data [$ k1] [$ k2]);
$ Data [$ k1] [$ k2] = str_replace ("", "", $ data [$ k1] [$ k2]);
$ Data [$ k1] [$ k2] = str_replace ("\ n ","
\ N ", $ data [$ k1] [$ k2]);
}
}
Else
{
$ Data [$ k1] = nl2br (htmlspecialchars ($ data [$ k1]);
$ Data [$ k1] = str_replace ("", "", $ data [$ k1]);
$ Data [$ k1] = str_replace ("\ n ","
\ N ", $ data [$ k1]);
}
}
}
Else
{
$ Data = nl2br (htmlspecialchars ($ data ));
$ Data = str_replace ("", "", $ data );
$ Data = str_replace ("\ n ","
\ N ", $ data );
}
Return $ data;
}
}
?>
The http://www.bkjia.com/PHPjc/317359.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/317359.htmlTechArticle code is as follows :? Php/*** page function: Common form verification classes * author: Happy With The Wind * creation Time: 2006-3-6 * QQ: 276624915 */classclass_post {// verify whether it is specified...