-2

I want to add new validation method to jquery validation that validates date in dd/mm/yyyy format ex(28/01/2015)

I tried :

$.validator.addMethod("dateFormat",function(value, element) {
    return value.match(/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012]) [\/\-]\d{4}$/);
 });

which is not working as expected.. any better way of doing it?

Sparky
  • 94,381
  • 25
  • 183
  • 265
monda
  • 3,529
  • 13
  • 52
  • 80
  • **What exactly does *"not working as expected"* mean?** No validation? Validation is incorrect? Console errors? – Sparky Jan 23 '15 at 18:51

1 Answers1

-1

I'm sorry I can't provide a more personal answer, but there's already a lot on this. Does this link help?

Javascript - Regex to validate date format

Example from linked answer:

var dateReg = /^\d{2}([./-])\d{2}\1\d{4}$/

"22-03-1981".match(dateReg) // matches
"22.03-1981".match(dateReg) // does not match
"22.03.1981".match(dateReg) // matches

Another link that might help:

Javascript date regex DD/MM/YYYY

Community
  • 1
  • 1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Ben Jan 23 '15 at 16:14
  • Updated with a valid example from one of the links. – João Miguel Brandão Jan 23 '15 at 16:16