Ais*_*ina 2 php regex posix-ere
鉴于模式^[a-zA-Z0-9 .\-_]+$和字符串te\\st,为什么匹配正面?我正在使用它来验证用户名,我不希望人们在他们的用户名中加入斜杠,它与URL混淆.
我正在调用ereg($pattern, $username),运行PHP版本5.2.8.
ereg很疯狂 我建议避免它.您应该尝试使用preg_match此:
$count = preg_match('/^[a-zA-Z0-9 .\-_]+$/', 'te/\st', $matches);
print_r($matches); // empty array (no matches)
print $count; // 0 (no matches)
Run Code Online (Sandbox Code Playgroud)