2016-05-16 149 views
-1

我在用戶輸入英文字符時顯示一條消息。該消息應顯示必須輸入波斯語字符。我爲此使用回調函數,但是當我填寫英文字符時,它不顯示消息(please enter %s in persian.)。爲什麼我的form_validation不起作用?

這是我的看法:

<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; 
} 
+3

你在說什麼? –

+1

你在**方法裏寫**方法完成第一個後寫你的方法並用'$ this-> METHODNAME'訪問並添加更多關於你的問題的信息 –

回答

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; 
} 
+0

我有它但是不起作用我只是把一部分我的代碼。 – Zoee