Guillaume Lavoie
Guillaume Lavoie

Reputation: 567

Javascript RegExp : How to detect space character?

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

Upvotes: 0

Views: 201

Answers (2)

aefxx
aefxx

Reputation: 25249

regexp = /^\d{4}\s\/\s\d{2}\s\/\s\d{2}$/g;

Upvotes: 1

Ofer Zelig
Ofer Zelig

Reputation: 17480

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

Upvotes: 0

Related Questions