仅在我的文本框中验证数字和字母

时间:2010-02-27 03:19:05

标签: php javascript html

愉快的一天每个人..我在我的php文件中有这个java脚本代码,其中我用它作为我的验证器..在我的文本框中的不同字段的输入...我唯一的问题是我不知道如何在我的名字和姓氏字段中创建只接受字母...的验证...期待任何帮助感谢有美好的一天...我也想知道如何只在我的领域接受数字超级谢谢^ ^,

以下是代码:

<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 个答案:

答案 0 :(得分:1)

仅限字母:/^[a-zA-Z]+$//^[a-z]+$/i

仅限数字:/^[0-9]+$/