PHP Common Forms Validation Class usage instance, PHP form validation instance
The example in this paper describes the use of PHP common forms validation class. Share to everyone for your reference. Specific as follows:
<?php/*** page function: Common Forms Validation Class * Author: Gladly with the wind * Qq:276624915*/class class_post{//Verify that the letter/number combination function Fun_text1 is the specified length ($num 1,$ Num2, $str) {Return (Preg_match ("/^[a-za-z0-9]{". $num 1. ",". $num 2. "} $/", $str))? True:false;} Verifies whether the numeric function fun_text2 for the specified length ($num 1, $num 2, $str) {return (Preg_match ("/^[0-9]{". $num 1. ",". $num 2. "} $/i ", $str))? True:false;} Verifies whether 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 the ID number function Fun_status ($STR) {return (Preg_match ('/(^ [\d]{15}|[ \d]{18}| [\d] {17}x) $)/', $str))? True:false;} Verify the 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 inbound Escape special character passed in value can be a string or 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 character incoming value can be a string or a/two-D array function Data_revert (& $data) {if (Is_array ($data)) {foreach ($data as $k 1 = $ V1) {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 the incoming value can be a string or a/two-dimensional array//Data_revert () should precede this method, the form contents do 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][$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;}}? >
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1019066.html www.bkjia.com true http://www.bkjia.com/PHPjc/1019066.html techarticle PHP Common Forms Validation class usages, PHP form Validation Example This article describes the PHP common forms validation class usage. Share to everyone for your reference. Specifically as follows: php/*** page action ...