php - 字符串长度验证php表单
问题描述
这是我检查该字段是否为空并且工作正常的代码,但是我想检查两者,如果它是空的并且它是否少于 10 个字符
<pre>
if(empty($_POST['comments'])){ $errors[]="Please enter a comment."; }
</pre>
我试过这个
<pre>
if(empty($_POST['comments'])){ $errors[]="Please enter a comment."; }
if(strlen($_POST['comments']) > 10){ $errors[]="Please enter a comment."; }
</pre>
然而,这两个都没有工作,所以我尝试了相同的结果,但他们都没有工作
<pre>
if(empty($_POST['comments']) && strlen($_POST['comments']) > 10)){ $errors[]="Your
comment must be longer than 10 characters."; }
</pre>
我也尝试过 mb_strlen ,但这并没有改变。
解决方案
推荐阅读
- angular - 使用公共模块文件夹的多个 Angular 应用程序
- powerbi - 如何在 Power BI 中合并多个表,同时附加一个包含表名称的新列?
- java - 当lib类获取键值时,如何修改属性文件中的值?
- javascript - 纹理是将音频数据传输到 GLSL 的唯一方法吗?
- erlang - 为什么我在运行 eunit 测试时会出错?
- ruby-on-rails - Rails 4:删除目录后如何重新创建 Postgres 数据库
- ubuntu - 如何让 orca 在 ubuntu 上的 Firefox 中阅读网页
- c++ - 为什么可以在析构函数中删除未初始化的指针,但不能在 main 中删除?
- powershell - 保持变量私有,但仍然在函数中使用它
- asp.net - 如何将 ID 参数从视图传递到控制器?