-8

I have to do client side validation(using javascript/JQuery) for the input value which should have date in dd/mm/yyyy format. Please share regular expression if exist. It should validate the date is proper in all context.

Thanks in advance, Ratnesh

Ratnesh Lal
  • 319
  • 4
  • 6
  • 17
  • 4
    Please do a bit of research, including the links in the Related section on this page (on the right). – Mat Nov 22 '11 at 13:50
  • 3
    You've shown no attempt to solve this problem yourself. We will, happily, provide help with your problems, but for the most part will not do your work for you. – David says reinstate Monica Nov 22 '11 at 13:51
  • Possible duplicate of [Regex to validate date format dd/mm/yyyy](http://stackoverflow.com/questions/15491894/regex-to-validate-date-format-dd-mm-yyyy) – rene Sep 03 '16 at 19:41

5 Answers5

1

try to use

/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/

or look at this the same question

Community
  • 1
  • 1
Serghei
  • 3,748
  • 2
  • 18
  • 33
0

Use

^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$

I was looking for the same thing and got it from here

This expression validates days from 01 to 31, months from 01 to 12 but it accepts any number with 4 digts for year (including 0000). And it returns true for wrong dates like 31/02/2015.

Use a regex online validator like this one in order to check if it suits you.

Susana Santos
  • 252
  • 1
  • 6
  • 16
0

http://www.regular-expressions.info/dates.html

http://blog.brijeshradhika.com/2010/10/jquery-validation-date-mmddyyyy-format.html

A lot of this in google. You should have tried to find it at least.

Surasin Tancharoen
  • 4,044
  • 3
  • 29
  • 34
  • I searched and found similar links. I need that validation can validate if such date can really exist or not – Ratnesh Lal Nov 22 '11 at 14:01
  • 2
    @RatneshLal, for your own good, please avoid something like this question. It did not show your effort to solve problems and people in here do not like that. Then you will be voted down. Then you will never have good 'reputation'. Then not many people will want to help you. People here have strong willing to help if you just show some efforts. – Surasin Tancharoen Nov 22 '11 at 14:07
0

Regex will validate your format, but won't validate if date makes logic sense (leap years and stuff). That's said:

Javascript date regex DD/MM/YYYY javascript regexp, validating date problem

and numerous others...

Community
  • 1
  • 1
Bartosz
  • 3,188
  • 18
  • 30
0

As an alternative to regular expressions you may wish to take a look at datejs

http://www.datejs.com

Using parse exact http://code.google.com/p/datejs/wiki/APIDocumentation#parseExact

you can do things like:

var myDate = Date.parseExact("19/12/2004", "dd/mm/yyyy"); 

And will return null, if the date cannot be parsed.

n.b. I haven't tested the code above, but it should work ok.

Alex KeySmith
  • 15,289
  • 6
  • 63
  • 143