0

I am trying to make a pattern that will return if a string has the following formating:

yyyy / mm / dd ( please note that they are 4 spaces in that string ).

The following code is what I have come with so far, but it still can't detect the space character. Any ideas how to make it work ?

RegExp( /^\d{4}[\s\/\s]\d{2}[\s\/\s]\d{2}$/g ).test( "1234 / 11 / 22" );    
RegExp( /^\d{4}[ \/ ]\d{2}[ \/ ]\d{2}$/g ).test( "1234 / 11 / 22" );

Thanks

1
  • Why are you using [] all over the place? I don't see a need for character classes here. Commented Apr 2, 2012 at 22:25

2 Answers 2

1
regexp = /^\d{4}\s\/\s\d{2}\s\/\s\d{2}$/g;
Sign up to request clarification or add additional context in comments.

1 Comment

It is common here to accept an answer if it solved your problem. Please consider accepting.
0
RegExp( /^\d{4}\s\/\s\d{2}\s\/\s\d{2}/g ).test( "1234 / 11 / 22" );

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.