Expand my Community achievements bar.

Date Validation

Avatar

Former Community Member

How do i restrict user from entering specific dates. Eg. Date of death= cannot be current date.

2 Replies

Avatar

Level 7

I think this can be as simple or as complex as you want it to be. You can simply do a comparison when the user exits the date field like:

//assuming that one field is named currentDate, and this check should be on the exit event of the date of death field

if (this.parent.currentDate.rawValue == this.rawValue) this.rawValue = "";

Assuming that there are no built-in functions, then you'd have to parse the rawValue of the dates to do a > or < verification. e.g., dateOfDeath > currentDate.

Avatar

Level 7

I played around with this. The rawValue's are written in scientific date form (if you're using date fields). e.g., 2013-05-17. So, the rawValue's can be compared as strings.

Let's say your two fields are called dateOfDeath and currentDate. Then say some joker comes along and tries to put in a date after today as the dateOfDeath.

If you put an if statement into the exit script for the dateOfDeath field, this.parent.currentDate.rawValue<=this.rawValue will return TRUE.

So, you can use this code to simply blank out the dateOfDeath field if someone does it wrong.

if (this.parent.DateField2.rawValue <= this.rawValue) this.rawValue = "";