Php
I added regular expression validation when registering the user name, but the Preg_match () function was always an error.
The code is as follows:
//在注册函数库里编写的函数:function check($username){ $pattern = '/[\<>\'\"\ \ \]/'; //匹配左右尖括号、英文单双引号、半角空格、全角空格 if(preg_match($pattern, $username)){ echo ""; }}//然后在注册页面调用$tmpArray = array();$tmpArray['username'] = check($_POST['username']);
As a result, I randomly entered a username AAA ' AAA in the user name input form, and after submitting the page header error: Warning:preg_match () [Function.preg-match]: compilation failed:missing Terminating] for character class at offset + in d:/.....
Excuse me, what is the reason for this error? I used IE11, Firefox38 all the same mistakes. Finally, in my editor, $pattern = '/[<>\ ' \ ' \ \]/' in the English single quotation marks show the escape pattern, but how to deal with it is still that way, this is what situation?
Thank you!