Checking String for illegal characters using regular expression

后端 未结 5 1719
猫巷女王i
猫巷女王i 2021-01-25 21:02

I want to check a for any illegal character using the following regular expression in PHP. Essentially, I want to allow only alphanumeric and underscore (_). Unfortunately the

5条回答
  •  一整个雨季
    2021-01-25 21:37

    If $username only has alphanumeric and underscore it will return TRUE

    if (preg_match("/^[a-z0-9_]+$/i", $username) )
    {
        return true;
    }
    

提交回复
热议问题