preg_match username validation regex allows > and < despite those characters not being whitelisted

前端 未结 2 1768
既然无缘
既然无缘 2020-12-20 03:50

I have this relatively simple regex for usernames

// Enforce that username has to be 3-100 characters, alphanumeric, and first character a letter.
// Possibi         


        
相关标签:
2条回答
  • 2020-12-20 04:06

    I think it's because of this: [+-_]

    You are including all chars between '+' and '_', try changing the order to [+_-] (putting the dash at the end) or escape the dash.

    0 讨论(0)
  • 2020-12-20 04:07

    +-_ is your problem. You need to escape the - in a character class or move it to the end or beginning of the class.

    For example:

    /^[a-z][a-z0-9@.+_-]{2,100}\z/i
    
    0 讨论(0)
提交回复
热议问题