好的,我正在检查一个字符串是否至少有4个字符,25个或更少的字符
我试着像这样使用strlen
$userNameSignupLength = strlen($userNameSignup);
else if($userNameSignupLength<4 && $userNameSignupLength>25) {
$userNameSignupError = "Must be between 4 to 25 characters long";
}但它不起作用。我做错什么了?
发布于 2010-03-22 22:26:10
使用strlen检查字符串的长度(以字节为单位)是正确的。但是一个数字不能同时小于4和大于25。请改用||:
if ($userNameSignupLength < 4 || $userNameSignupLength > 25)现在,如果数字小于4或大于25,则满足条件。
发布于 2010-03-22 22:26:47
将&&更改为||
else if ($userNameSignupLength<4 || $userNameSignupLength>25)发布于 2010-03-22 22:28:03
我想你需要一个OR:
else if($userNameSignupLength < 4 || $userNameSignupLength > 25) {正如Gumbo所说,长度不可能既小于4又大于25。&&的意思是and。
https://stackoverflow.com/questions/2492926
复制相似问题