php-php Preg_match () error when user registers for debugging

Source: Internet
Author: User
Keywords Php
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!

  • 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.