gpt4 book ai didi

php - 如何使用 ctype_alnum() 允许下划线和破折号?

转载 作者:可可西里 更新时间:2023-10-31 23:02:47 26 4
gpt4 key购买 nike

如何在使用 ctype_alnum() 时将 _- 的异常(exception)添加为有效字符? ?

我有以下代码:

if ( ctype_alnum ($username) ) {

return TRUE;

} elseif (!ctype_alnum ($username)) {

$this->form_validation->set_message(
'_check_username',
'Invalid username! Alphanumerics only.'
);

return FALSE;
}

最佳答案

由于 ctype_alnum 只验证字母数字字符,试试这个:

$sUser = 'my_username01';
$aValid = array('-', '_');

if(!ctype_alnum(str_replace($aValid, '', $sUser))) {
echo 'Your username is not properly formatted.';
}

关于php - 如何使用 ctype_alnum() 允许下划线和破折号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7198958/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com