0

I need to do a text input validation in javascript with the below rules.

Could you please let me know the regular expression for this?

the Text Input should be exactly 8 long, and it should meet the following conditions:

Starts with 3 letters Then and Underscore and ends with 4 Digits I have tried this : /^[a-z A-Z]{3} - [0-9]{4} *$/ but it did not work Thank you

1
  • While @PeterNoges has already answered your question, there many online tools out there which help you build regexp easily, such as this one.
    – arut
    Dec 31 '20 at 5:46
1

do these work? One is underscore, one is hyphen based. Typed from my phone.

var match = yourStringVariable.match(/(^[a-z A-Z]{3} - [0-9]{4})/i);

var match = yourStringVariable.match(/(^[a-z A-Z]{3}_[0-9]{4})/i);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.