Form Text Field Input Mask

I need to create JavaScript validation for a form input text field.

The format of the text should be:

AB18-1234

It's been awhile since I've done this so I need some quick pointers to get me started.
Thank You!
Crystal RouseTask LeadAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CamilliaCommented:
You can use regex to do it. Here's an example Example
Crystal RouseTask LeadAuthor Commented:
If I'm understanding Regular Expressions, I have:

\D{2}+[0-9]{2}-?\d{4}$

Do I need to include ^ to start the line?
What is the symbol for a number only, special character such as a hyphen?
Eranga JayalatharachchiTech LeadCommented:
Use
^[A-Z]{2}[0-9]{2}-[0-9]{4}$

Open in new window

It will match two capital letters followed by two digits followed by a hyphen followed by four digits exactly - nothing less, nothing more.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sunil KumarCommented:
Please check the below given link may be it will be helpfull for you.
https://www.npmjs.com/package/Click Hereinputmask

regards
php interview questions
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.