Php-PHP preg_match () error during user registration and debugging

Source: Internet
Author: User
When registering a user name, I added regular expression verification, but the code for matching in the preg_match () function is always incorrect: & quot; the function written in the registration function library: functioncheck ($ username) {$ pattern & #39; [& lt; & gt; & #39; & quot;] & #39 ;; matching left and right angle brackets, single and double quotation marks, half-width spaces, and full-width spaces if (preg_match ($ pattern, $ username) {echo & quot; alert (& #39; Error: contains php

During user name registration, I added regular expression verification, but there is always an error in matching in the preg_match () function.
The code is as follows:

// Function written in the registration function library: function check ($ username) {$ pattern = '/[\ <> \' \ "\]/'; // Match left and right angle brackets, single and double quotation marks, half-width spaces, and full-width spaces if (preg_match ($ pattern, $ username) {echo "script alert ('Error: contain sensitive character! '); History. back (); script ";}}// then call $ tmpArray = array () on the registration page (); $ tmpArray ['username'] = check ($ _ POST ['username']);

As a result, I randomly enter a username aaa 'AAA in the username input form. after submission, an error is displayed in the header of the page: Warning: preg_match () [function. preg-match]: Compilation failed: missing terminating] for character class at offset 14 in D :/........

What is the cause of this error? When I use IE11 and Firefox38, the same error occurs. Finally, in my editor, the single quotes in $ pattern = '/[<> \' \ "\]/'show the escape form, but what is the situation?

Thank you!

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.