2

Hi all having a little problem with regex and Jquery in checking that a date will work correctly.

Currently it doesn't accept the number 01 but does 02+ but works as expected with ranges above 31.

this is the js fiddle page. http://jsfiddle.net/b3aHt/

Thanks

1 Answer 1

3

01 fails because of dob < 2.

I don't think regular expressions make for a very neat solution here. I would rather test

if(dob.length != 2 || isNaN(dob) || dob < 0 || dob > 31) {
   // not between 01 and 31
}
Sign up to request clarification or add additional context in comments.

2 Comments

oh that was just to check that dobs length was greater than to should that be dob.length < 2?
Thanks David. I like your neater solution too.

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.