0

I need to create an additional method for the jQuery validate plugin, but I'm not great with regular expressions. What I need is to check if a text input is typed like I50xxxx OR i50xxxx, where xxxx are alphanumerics (0000 to 9999)

I made this :

jQuery.validator.addMethod("matricule", function(value, element) {
    return this.optional(element) || /^I50\d{4}$/.test(value);
}, "Entrez un matricule valide (I50xxxx)");

It's Ok to check the first type, but not both. Can you help me?

1
  • 2
    (0000 to 9999) are numerics not alphanumerics Commented Jul 31, 2015 at 9:37

1 Answer 1

2

Add i modifier in order to perform a case-insensitive search.

/^I50\d{4}$/i.test(value);

or

/^[iI]50\d{4}$/.test(value);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.