2010-02-27 139 views
4

愉快的一天大家..我有這個Java腳本代碼在我的PHP文件,其中我用這個作爲我的驗證..在我的文本框中的不同領域的輸入......我唯一的問題是我不知道如何創建一個驗證,只接受字母......在我的名字和姓氏字段...期待任何援助謝謝有一個愉快的一天...我也想知道如何接受數字只在我場超級感謝^^,只驗證數字和字母只在我的文本框

下面的代碼:

<script type='text/javascript'> 

$(document).ready(function() 
    { 
     $('#employee_form').validate({ 
     submitHandler:function(form) 
     { 
      $(form).ajaxSubmit({ 
      success:function(response) 
      { 
      tb_remove(); 
      post_person_form_submit(response); 
      }, 
     dataType:'json' 
     }); 

    }, 

    errorLabelContainer: "#error_message_box", 
    wrapper: "li", 
    rules: 
    { 
     first_name: "required", 
     last_name: "required", 

     username: 
     { 
      required:true, 
      minlength: 5 
     }, 

     password: 
     { 
      <?php 
      if($person_info->person_id == "") 
      { 
      ?> 
      required:true, 
      <?php 
      } 
      ?> 
      minlength: 8 
     }, 
     repeat_password: 
     { 
      equalTo: "#password" 
     }, 
     email: 
     {    
      required:true, 
      email: "email" 
     } 
    }, 
    messages: 
    { 
     first_name: "<?php echo $this->lang->line('common_first_name_required'); ?>", 
     last_name: "<?php echo $this->lang->line('common_last_name_required'); ?>", 
     username: 
     { 
      required: "<?php echo $this->lang->line('employees_username_required'); ?>", 
      minlength: "<?php echo $this->lang->line('employees_username_minlength'); ?>" 
     }, 

     password: 
     { 
      <?php 
      if($person_info->person_id == "") 
      { 
      ?> 
      required:"<?php echo $this->lang->line('employees_password_required'); ?>", 
      <?php 
      } 
      ?> 
      minlength: "<?php echo $this->lang->line('employees_password_minlength'); ?>" 
     }, 
     repeat_password: 
     { 
      equalTo: "<?php echo $this->lang->line('employees_password_must_match'); ?>" 
     }, 

     email: 
     { 
      required: "<?php echo $this->lang->line('common_email_name_required'); ?>", 
      email: "<?php echo $this->lang->line('common_email_invalid_format'); ?>" 
     } 

    } 
    }); 
}); 
</script> 

回答

1

只有字母:/^[a-zA-Z]+$//^[a-z]+$/i

僅數:/^[0-9]+$/

+0

謝謝回答^ ^,我會只是試試這個..檢查是否正常工作..再次感謝 – PaLoS 2010-02-27 03:28:43

+0

或者只是'/^\ d + $ /'爲數字 – 2010-02-27 09:09:07