如果用户输入英文字符,我会显示一条消息。该消息应显示必须输入波斯字符。我为此使用回调函数,但是当我填写英文字符时,它不会显示消息(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;
}
答案 0 :(得分: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;
}