Table Tanzhong Validation and file upload verification

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.