Form Regular Expression verification and file upload verification, form File Upload Verification
Form Regular Expression verification is mainly used to filter form submission information and prevent SQL injection (such as logon interface). uploaded files also need to be verified by the filename suffix and size, below is a simple form verification
Header ("Content-type: text/html; charset = UTF-8"); $ user = isset ($ _ POST ['user'])? $ _ POST ['user']: null; $ password = isset ($ _ POST ['Password'])? $ _ POST ['Password']: null; $ arr = array ('png ', 'gif', 'jpg '); $ uploads = move_uploaded_file ($ _ FILES ['face'] ['tmp _ name'], 'uploads /'. $ _ FILES ['face'] ['name']); $ file = 'uploads /'. $ _ FILES ['face'] ['name']; if ($ uploads) {echo 'uploaded successfully';} if (! Preg_match ("/^ [\ x {4e00}-\ x {9fa5}] + $/u", $ user )) {// check whether the user name is composed of Chinese characters. echo "the user name can only consist of Chinese characters! "; Die;} else if (! Preg_match ("/^ [\ x {4e00}-\ x {9fa5} A-Za-z0-9 _] + $/u", $ password )) {// Regular Expression check if the password contains invalid characters. The echo password cannot contain special characters! '; Die;} else if (! In_array (pathinfo ($ file, PATHINFO_EXTENSION), $ arr) {echo "incorrect file format"; die;} else {echo 'allow registration! ';}
With common php Regular Expressions:
Match China zip code: [1-9] \ d {5 }(?! \ D)
Matched ID card: \ d {15} | \ d {18}
Matched IP Address: \ d + \. \ d +
Regular Expression matching URL: [a-zA-z] +: // [^ \ s] *
The regular expression matching the Email address: \ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\. \ w + ([-.] \ w + )*
Regular Expression matching Chinese characters: [\ u4e00-\ u9fa5]
Function:
Preg_match (): the first parameter is a regular rule, the second is a verified string, and a Boolean value is returned.
Preg_replace (): replace the characters that match the regular rules in a string.
The above section describes the form Regular Expression verification and file upload verification functions. I hope this will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!