问题描述:

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

网友答案:

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

网友答案:

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}$
相关阅读:
Top