LearningThe PHP verification form code is as follows:
- <?Php
- 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] {} $/", $ 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 }-))? (0d {2, 3}) | 0d {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; return (preg_match ("/^ (d {3}) | (d {3 }-))? (0d {2, 3}) | 0d {2, 3 }-)? [1-9] d {6, 7} $/", $ str ))? True: false;
- }
-
- // 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 ("","<Br>", $ Data [$ k1] [$ k2]);
- }
- }
- Else
- {
- $ Data [$ k1] = nl2br (htmlspecialchars ($ data [$ k1]);
- $ Data [$ k1] = str_replace ("", "", $ data [$ k1]);
- $ Data [$ k1] = str_replace ("","<Br>", $ Data [$ k1]);
- }
- }
- }
- Else
- {
- $Data=Nl2br(Htmlspecialchars ($ data ));
- $Data=Str_replace("", "", $ Data );
- $Data=Str_replace("","<Br>", $ Data );
- }
- Return $ 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 ("","<Br>", $ Data [$ k1] [$ k2]);
- }
- }
- Else
- {
- $ Data [$ k1] = nl2br (htmlspecialchars ($ data [$ k1]);
- $ Data [$ k1] = str_replace ("", "", $ data [$ k1]);
- $ Data [$ k1] = str_replace ("","<Br>", $ Data [$ k1]);
- }
- }
- }
- Else
- {
- $Data=Nl2br(Htmlspecialchars ($ data ));
- $Data=Str_replace("", "", $ Data );
- $Data=Str_replace("","<Br>", $ Data );
- }
- Return $ data;
- }
- }
- ?>
The above code is related to the PHP verification form implementation method.