0

I am very new to regex and in researching for an answer found many cryptic answers, I hope someone here can lend a hand. I am validating an input field for MM/DD and am limiting the input to numbers only with

ng-pattern="/^0|[1-9]\d*$/"

The format we are using in the app is MM/YY, with the '/' automatically being entered with jQuery .keypress function. For some reason the field validates fine until after the '/' and then it only validates the last two numbers.

Is there a pattern that will essentially ignore the '/' so the entire field can be validated for numbers only?

Thank you for your help.

1 Answer 1

1

Here is the corrected regexp:

/^\d{2}\/\d{2}$/

It means start 2 integers slash 2 integers end

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.