I’m trying to use javascript regex to validate a date input, but it is returning valid dates as invalid. I’m not an expert on regex so I don’t know what is wrong with it:
/^([0-9]d{2})+(\.|-|\/)+([0-9]d{2})+(\.|-|\/)+([0-9]d{4})+$/
I want these date formats to be accepted:
23/04/2001
23-04-2001
23.04.2001
Originally I had this, but it was accepting dates with other characters on the end like 23/04/2001jhsdgf:
/\d{2}(\.|-|\/)\d{2}(\.|-|\/)\d{4}/;
Take your original regex and just add the
^and$from your new one to it. Problem solved.EDIT: Although, really, the
(\.|-|\/)is a mess and should be[.\/-]instead.EDIT 2: That said, if you make the first one
([.\/-])then you can replace the second one with\1and then it would require both separators to be the same.