1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

jQuery Validator Issue

Discussion in 'HTML, Graphics & Programming' started by Goldy, Apr 26, 2018.

  1. Goldy

    Wise Guy

    Joined: Mar 30, 2004

    Posts: 1,147

    Location: West Wing

    Hi all,

    I have this bit of code that checks if the user has entered a 5 digit number in a box.

    Code:
    jQuery.validator.addMethod("IDValidation", function (value, element) {
    
                return /^\d{5}$/.test(value);
            }, "Incorrect Code");
    I want to change it so that it only checks the user has entered 5 characters (digits or alphabet). I honestly dont know my way around jQuery or PHP at all!
     
  2. philldutton

    Associate

    Joined: Apr 30, 2004

    Posts: 43

    Something like:
    Code:
    jQuery.validator.addMethod("IDValidation", function (value, element) {
    
                return /^[0-9a-z]{5}$/i.test(value);
            }, "Incorrect Code");
     
  3. Goldy

    Wise Guy

    Joined: Mar 30, 2004

    Posts: 1,147

    Location: West Wing

    Thanks Phil! This worked :)

    Code:
                return /^\[0-9a-z]{5}$/i.test(value);
            }, "Incorrect Code");