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!