views:

185

answers:

1

Pleasant day everyone.. i have this java script code in my php file wherein i used this as my validator..for the inputs in different fields in my textbox... my only problem is i don't know how to create a validation that only accepts letters... in my first name and last name field ...looking forward for any assistance thanks have a nice day... i also wanted to know how about accepting numbers only in my field super thanks ^^,

Here's the code:

<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: 

only letters : /^[a-zA-Z]+$/ or /^[a-z]+$/i

only numbers: /^[0-9]+$/

ghostdog74
thanks for answering ^^, i'll just try this one.. check if it works .. thanks again
PaLoS
Or just `/^\d+$/` for the digits
Justin Johnson