我一直在尝试让reg_match
用户名只接受a-z
, A-Z
, 0-9
, -
,_
不幸的是我所有的尝试都失败了。
function usernameValidation($username){
$re = "/[\w_-]/g";
return preg_match($re, $username);
}
$username = "skjdasASD345-_adadasda";
if(usernameValidation($username)){
echo "success!!";
}else{
echo "Fail!"; //it always return fail.
}
我的代码总是返回失败,谁能告诉我我做错了什么?