Php表单验证的最小字符需要避免空白
Php form validation minimum character need avoid white space?
在我们的人力资源系统中,我放了一个验证用户必须至少放8个字母的注释。但如果他们不放,他们就不能打卡。但他们正在做的是放8个空白,他们可以打卡:(所以我想限制他们放钞票,避免空白
if(empty($openPunch)){
$currentTime = $req->time;
if (strtotime($currentTime) >= strtotime('09:30')){
if(strlen($req->note) < 8){
$time = (strtotime($currentTime) - strtotime('09:30'));
$minutes = floor($time / 60);
$minute = $minutes%60;
$hours = floor($time / 3600);
return new IceResponse(IceResponse::ERROR,"Today you are late ".$hours.":".$minute." Hours You Can't Punch in without Fill the Correct Reason");
}
}
$openPunch = new Attendance();
}
尝试修剪字符串,如W3 Schools js修剪示例
我没有发表评论的特权,这就是为什么我发布这个作为一个答案。。。
希望这对你有帮助。。
正如@Julie Pelletier评论的那样,它实际上并没有完全解决问题…!:D
谢谢。。!
使用trim()函数
trim()函数从字符串两侧删除空白和其他预定义字符。
http://www.w3schools.com/php/func_string_trim.asp
if(empty($openPunch)){
$currentTime = $req->time;
if (strtotime($currentTime) >= strtotime('09:30')){
if(strlen(trim($req->note)) < 8){
$time = (strtotime($currentTime) - strtotime('09:30'));
$minutes = floor($time / 60);
$minute = $minutes%60;
$hours = floor($time / 3600);
return new IceResponse(IceResponse::ERROR,"Today you are late ".$hours.":".$minute." Hours You Can't Punch in without Fill the Correct Reason");
}
}
$openPunch = new Attendance();
}
相关文章:
- 不同浏览器中的空白字符正则表达式行为
- JSON解析意外的非空白字符
- 为什么在尝试在 javascript 中对 URI 组件的保留字符进行编码时出现空白 %3 字符
- 输入表单中不允许有空白字符/空格
- 如何知道目标字符串之前是否有非空白字符
- 由于空白字符,Java脚本失败
- angular -双簧管+ NodeJS流错误前非空白字符
- 了解RegEx空白字符
- JavaScript对所有多行空格和其他空白字符使用regex进行替换
- 如何显示空白字符.但在选择文本时省略
- 用一个空白字符替换连续的空白
- responseText包含额外的空白字符(换行,换行),如何防止和删除它们
- JSON数据第1行第991列后面的非空白字符
- Javascript regex计算空白字符
- 无法使正则表达式能够删除第一个空白字符
- 替换所有空白字符
- JSON.parse:JSON数据后出现意外的非空白字符
- Regex-若包含单词,那个么最后一个字符必须是空白字符
- JavaScript正则表达式空白字符
- 在rails中保留文本区域白色编辑中的空白字符