Copy CodeThe code is as follows:
/**
* Page function: Common Forms Validation Class
* Author: Gladly with the wind
* Setup Time: 2006-3-6
* qq:276624915
*/
Class Class_post
{
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)
{
Preg_match ("/^[\xa0-\xff]{1,4}$/", $string);
Return (Preg_match ("/^ ([\x81-\xfe][\x40-\xfe]) {". $num 1. ",". $num 2. "} $/", $str))? True:false;
}
Verify the ID number
function Fun_status ($STR)
{
Return (Preg_match ('/(^ [\d]{15}|[ \d]{18}| [\d] {17}x) $)/', $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 ("/^ (\d{3}\) | ( \d{3}\-))? (\ (0\d{2,3}\) |0\d{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;
}
Verify the URL address
function Fun_url ($STR)
{
Return (Preg_match ("/^http:\/\/[a-za-z0-9]+\.[ a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!] * ([^<>\ "]) *$/", $str))? True:false;
}
Data inbound Escape special character incoming 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 out-of-Library restore special characters incoming values can be strings or one/two-dimensional arrays
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 can be strings or one/two-dimensional arrays
You should data_revert () before executing this method, and the contents of the form need not be restored
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][$k 2]);
$data [$k 1][$k 2]=str_replace ("", "", $data [$k 1][$k 2]);
$data [$k 1][$k 2]=str_replace ("\ n", "
\ 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", "
\ n ", $data [$k 1]);
}
}
}
Else
{
$data =nl2br (Htmlspecialchars ($data));
$data =str_replace ("", "", $data);
$data =str_replace ("\ n", "
\ n ", $data);
}
Return $data;
}
}
?>
The above describes the jquery form validation commonly used forms validation class, with this, the general verification is all aligned. , including the content of the jquery form verification, I hope that the PHP tutorial interested in a friend helpful.