How I can validate date of birth?
Month-Date-Year
Example: 11-21-1960
Thanks
Views
Replies
Total Likes
You could use a date object that allows you to set a display and edit pattern that would match the date format you want.
Views
Replies
Total Likes
You could use a regular expression:
E.g.
var dateRegExp = "^(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-(19|20)\d\d$"; // mm-dd-yyyy
if (oField.rawValue.search(dateRegExp) === -1) {
// error!
}
Or you could use a date object as suggested in the previous post, but also stop the user from typing in a date so they will be forced to use the date selection box. This would ensure that the date is always in the correct format. To stop the user from typing in data, put the following code in the change event for the field:
if (xfa.event.change.length == 1) {
xfa.event.change = "";
}
Views
Replies
Total Likes
On Validate event:
var dateRegExp = "^(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-(19|20)\d\d$"; // mm-dd-yyyy
if (oField.rawValue.search(dateRegExp) === -1) {
// error!
}
I am getting a error if I type: 11-12-2011
What can be wrong?
Thanks
Views
Replies
Total Likes
Sorry, the backslashes must be escaped, i.e. add an additional backslash to the start of "\d" (or replace "\d" with "[0-9]"). E.g:
var dateRegExp = "^(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-(19|20)\\d\\d$"; // mm-dd-yyyy
if (this.rawValue.search(dateRegExp) === -1) {
false;
}
else {
true;
}
Views
Replies
Total Likes
Thank you Jason now works fine!
Views
Replies
Total Likes
Views
Likes
Replies