The examples in this article describe the usage of PHP common form validation classes. Share to everyone for your reference. as follows:
<?php/** * page role: Common form Validation class * Author: Gladly with the wind * qq:276624915/class Class_post {//Verify that the letter/number combination function for the specified length fun_text1 ($num 1, $num 2, $str) {return (Preg_match ("/^[a-za-z0-9]{". $num 1. ",". $num 2. "}
$/", $str))? True:false; //Verify that the specified length numeric function fun_text2 ($num 1, $num 2, $str) {return Preg_match ("/^[0-9]{". $num 1. ",". $num 2. "}
$/i ", $str))? True:false;
//Verify if the specified length Kanji function fun_font ($num 1, $num 2, $STR) {//Preg_match ("/^[\xa0-\xff]{1,4}$/", $string); Return (Preg_match/^ ([\x81-\xfe][\x40-\xfe]) {. $num 1. ",". $num 2. "}
$/", $str))? True:false; //Verify ID number function Fun_status ($STR) {return Preg_match ('/(^ \d]{15}|[ \d]{18}| [\d]
{17}x) $)/', $str) ' True:false; //Verify mail 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 (/^) | ((\d{3}\) | \d{3}\-))? (\ (0\d{2,3}\) |0\d{2,3}-)?
[1-9]\d{6,7}$/, $str)] true:false; //Verify Zip function Fun_zip ($str) {return (Preg_match) ("/^[1-9]\d{5}$/", $str))? True:false; }//Verify URL address function Fun_url ($str) {return Preg_match ("/^http:\/\/[a-za-z0-9]+\.[ a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!]
* ([^<>\ "\]) *$/", $str))? True:false; ///Data warehousing escape special characters incoming values can be string or one-dimensional Array function Data_join (& $data) {if (GET_MAGIC_QUOTES_GPC () = False) {if Is_arra
Y ($data)) {foreach ($data as $k => $v) {$data [$k] = addslashes ($v);
} else {$data = Addslashes ($data);
} return $data; }//Database restore special characters incoming value can be a string or a/two D array function Data_revert (& $data) {if (Is_array ($data)) {foreach ($data as $k 1
=> $v 1) {if (Is_array ($v 1)) {foreach ($v 1 as $k 2 => $v 2) {$data [$k 1][$k 2] = stripslashes ($v 2);
} else {$data [$k 1] = stripslashes ($v 1);
}} else {$data = Stripslashes ($data);
return $data; }//Data display the restore data format is primarily used for content output incoming values should be Data_revert () before executing this method for a string or a/two D array, and the form content does not need this restore function data_show (& $data) {if is_ Array ($data)) {foreach($data as $k 1 => $v 1) {if (Is_array ($v 1)) {foreach ($v 1 as $k 2 => $v 2) {$data [$k 1][$k 2]=nl2br (htmlspecialchars $data [$k 1][$
K2]));
$data [$k 1][$k 2]=str_replace ("", "", $data [$k 1][$k 2]);
$data [$k 1][$k 2]=str_replace ("\ n", "<br>\n", $data [$k 1][$k 2]);
} else {$data [$k 1]=nl2br (Htmlspecialchars ($data [$k 1]));
$data [$k 1]=str_replace ("", "", $data [$k 1]);
$data [$k 1]=str_replace ("\ n", "<br>\n", $data [$k 1]);
}} else {$data =nl2br (Htmlspecialchars ($data));
$data =str_replace ("", "", $data);
$data =str_replace ("\ n", "<br>\n", $data);
return $data;
}}?>
I hope this article will help you with your PHP programming.