Skip to content Skip to sidebar Skip to footer

Javascript Regular Expression To Match X Digits Only

Can someone help my pea brain figure out why my simple regular expression is not working as I am expecting/wanting it to. I want to match a date format of MM/DD/YYYY with exactly 2

Solution 1:

need to specify start and end of string

/^\d{4}$/

Solution 2:

try this ^\d{1,2}\/\d{1,2}\/\d{4}$

Post a Comment for "Javascript Regular Expression To Match X Digits Only"