【问题标题】:why my form_validation doesn't work?为什么我的 form_validation 不起作用?
【发布时间】:2016-05-16 10:17:49
【问题描述】:

如果用户输入英文字符,则显示一条消息。消息应显示必须输入波斯字符。我为此使用了回调函数,但是当我填写英文字符时,它不会显示消息(please enter %s in persian.)。

这是我的看法:

<div class="row">
    <div class="form-group">
        <div class="col-md-2">
            <label>mantaghe<span style="color:red">*</span></label> 
        </div> 
        <div class="col-md-4 col-md-pull-1">
            <input class="form-control" id="mantaghe" name="mantaghe"></input>
            <?php echo form_error('mantaghe'); ?>
        </div>
   </div>
</div>

我的控制器:

public function show_info()
{
   $this->form_validation->set_rules('mantaghe', 'mantaghe ',                     
   'required|callback_persian_check');
}
function persian_check()
{       
    $username = $this->input->post('mantaghe');
    if (!preg_match('/^[^\x{600}-\x{6FF}]+$/u',$username))
    {
        $this->form_validation->set_message('persian_check'," please enter %s in persian");
        return false;
    }
    else return true;
}

【问题讨论】:

  • 你在说什么?
  • 您在方法中编写方法在完成第一个后编写您的方法并使用$this-&gt;METHODNAME 访问并添加有关您的问题的更多信息

标签: php codeigniter validation


【解决方案1】:

如下修改

function persian_check()
{
    $username = $this->input->post('mantaghe');
    if (!preg_match('/^[آ ا ب پ ت ث ج چ ح خ د ذ ر ز ژ س ش ص ض ط ظ ع غ ف ق ک گ ل م ن و ه ی]/',$username))
        {
            $this->form_validation->set_message('persian_check'," please enter %s in persian");
            return false;
         }
            else
                return true;
}

【讨论】:

  • 我有它,但不起作用我只是放了一部分代码。
猜你喜欢
  • 2013-05-04
  • 2020-03-12
  • 2015-02-26
  • 2014-12-16
  • 1970-01-01
  • 2011-03-05
  • 1970-01-01
  • 2015-09-25
  • 2018-03-05
相关资源
最近更新 更多