Validate username as alphanumeric with underscores

后端 未结 6 1608
梦谈多话
梦谈多话 2020-12-04 21:54

On my registration page I need to validate the usernames as alphanumeric only, but also with optional underscores. I\'ve come up with this:

function validate         


        
6条回答
  •  伪装坚强ぢ
    2020-12-04 22:30

    Your own solution is perfectly fine.

    preg_match uses Perl-like regular expressions, in which the character class \w defined to match exactly what you need:

    \w - Match a "word" character (alphanumeric plus "_")

    (source)

提交回复
热议问题