为什么赢了';我的字母数字验证规则在CakePHP模型中不起作用吗?
我已经在下面为我的字段进行了验证 我的字段是标题、内容为什么赢了';我的字母数字验证规则在CakePHP模型中不起作用吗?,php,cakephp,Php,Cakephp,我已经在下面为我的字段进行了验证 我的字段是标题、内容 var $validate = array('title' =>array('alphaNumeric'=>array('rule'=>'alphaNumeric','required'=>'true','message'=>'Enter a title for this post',)), 'content'=>array('alphaNumeric'=>
var $validate = array('title' =>array('alphaNumeric'=>array('rule'=>'alphaNumeric','required'=>'true','message'=>'Enter a title for this post',)),
'content'=>array('alphaNumeric'=>array('rule'=>'alphaNumeric','required'=>'true','message'=>'Enter some content for this post',)));
但每当我在表单中输入一些文本并尝试提交时,就会显示错误消息
验证有什么问题吗
这是我的表格
<h2> Add a Post Here </h2>
Please fill in all the fields.
<?php
echo $this->form->create('Post');
echo $this->form->error('Post.title');
echo $this->form- >input('Post.title',array('id'=>'posttitle','label'=>'title','size'=>'50','maxlength'=>'255','error'=>false));
echo $this->form->error('Post.content');
echo $this->form->input('Post.content',array('id'=>'postcontent','type'=>'textarea','label'=>'Content:','rows'=>'10','error'=>false));
echo $this->form->end(array('label'=>'Submit Post'));
?>
在此处添加帖子
请填写所有字段。
您可以使用自定义正则表达式
'rule' => array('custom', '[a-zA-Z0-9, ]+'),
我必须按如下方式更改正则表达式才能使其工作
'alphaNumeric' => array(
'rule' => array('custom', '/[a-zA-Z0-9, ]+/'),
'message' => 'Only letters and numbers allowed',
为什么内置的字母数字规则不能做到这一点呢?你能在问题中发布表单吗?如果你用$this->form->input('title')代替$this->form->input('post.title',..),会不会出现错误?哦,我知道了…我用了','。现在如何允许,上述字段中的空格和其他字符???