Table Tanzhong Validation is mainly used to filter the form submission information, prevent SQL injection (such as login interface), upload the file also need to do file name suffix and size to verify, the following is a simple form validation
1 Header("Content-type:text/html;charset=utf-8");2 $user=isset($_post[' User ']?$_post[' User ']:NULL;3 $password=isset($_post[' Password '])?$_post[' Password ']:NULL;4 $arr=Array(' PNG ', ' gif ', ' jpg ');5 $uploads=Move_uploaded_file($_files[' Face '] [' Tmp_name '], ' uploads/'.$_files[' Face '] [' Name ']);6 $file= ' uploads/'.$_files[' Face '] [' Name '];7 if($uploads){8 9 Echo' Upload success ';Ten } One if(!Preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$user)){ A - //regular check whether the user name is a whole Chinese character composition - Echo"User name can only be made up of pure Chinese characters!" "; the die; - -}Else if(!Preg_match("/^[\x{4e00}-\x{9fa5}a-za-z0-9_]+$/u",$password)){ - + //Regular Check if password contains illegal characters - Echo' Password cannot contain special characters! ‘; + die; A at}Else if(!In_array(PathInfo($file, pathinfo_extension),$arr)){ - - - Echo"File format is incorrect"; - die; - in}Else{ - to Echo' Allow registration! ‘; + -}
Common PHP Regular expressions are included:
Match China postcode: [1-9]\d{5} (?! \d)
Match ID: \d{15}|\d{18}
Match IP Address: \d+\.\d+\.\d+\.\d+
Regular expression matching URL URL: [a-za-z]+://[^\s]*
Regular expression matching email address: \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *
Regular expressions that match Chinese characters: [\U4E00-\U9FA5]
Function:
Preg_match (): The first parameter is a regular rule, the second is a validated string, and a Boolean value is returned
Preg_replace (): Character substitution for a character in a string that is echoed by a regular rule
Table Tanzhong Validation and file upload verification