2

Possible Duplicate:
Javascript date regex DD/MM/YYYY

i'm using this validation :-jquery validation engine

and by default validation function for date format is :-

 "date": {
                    "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/,
                    "alertText": "* Invalid date, must be in YYYY-MM-DD format"
                },

in YYYY-MM-DD format , i want to change this to DD-MM-YYYY

can anyone help me, to rewrite that function again

Community
  • 1
  • 1
vir
  • 1,081
  • 4
  • 19
  • 31
  • Look the answer here.. http://stackoverflow.com/questions/5465375/javascript-date-regex-dd-mm-yyyy – Murtaza May 23 '12 at 05:43

2 Answers2

2

use this link for date regex

//match date in format MM/DD/YYYY
var dateMMDDYYYRegex = '^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$';

check for more help click here- http://www.jquery4u.com/syntax/jquery-basic-regex-selector-examples/#.T70st0VYvg8

Community
  • 1
  • 1
Anupam
  • 200
  • 1
  • 4
1

Suppose, you are using Jquery Validator plugin to validate form fields and now you want to validate date field with custom format like mm/dd/yyyy or dd/mm/yyyy or dd-mm-yyyy or mm-dd-yyyy then there is no way to do by passing parameters.

Currently, Jquery Validator plugin is not allowing to define date format for validation.

In this case, you need to add one custom function and you need to write date format validation code in it and need to pass that function as parameter for that field in validate rule function.

http://triotips.com/programming/jquery/jquery-validate-plugin-custom-date-format-validation-394.html

replace with this and try

/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$
Javascript Coder
  • 5,691
  • 8
  • 52
  • 98