views:

69

answers:

1

Hi,

I am new to jquery and creating login form.One of the condition for the 'user name' is that, the first letter should not start with a number. How to do this using jquery?

thanks in advance.

+1  A: 

I assume you use jquery validation plugin. On the document ready function add below code.

$("#your-form-id").validate(({
      rules: {
        "userid": {
            required: true,
            uidValid:true// Add custom rule to validate userid field
        }
 }));

// Add custom validation method to validate user id
// Change regular expression according to your need
    $.validator.addMethod("uidValid", function(uid, element) {
        return (this.optional(element) || uid.match(/^[a-z][a-z0-9]*$/i));
    }, "Please specify a valid user id");

If you are not using jquery validation plugin,you can bind an event to onkeypress event of your userid input field ( and on the submit event of the form) and check whether it is match with relevant regular expression. But It will be lot more easier to use validation plugin than manually coding it.

Manjula
hi,Thanks...it works
Ra