Expand my Community achievements bar.

SOLVED

How to validate a date in a validation script

Avatar

Level 2

I have a date field for which I have set a validation pattern using its Object palette i.e. Object > Value tab > Validation Pattern > Validation tab. The validation pattern I have there is simply 'date{YYYY-MMM-DD}' with an error message set in the Validation Pattern Message box.

How do I perform this same validation using a javascript in the Validation event?

I'd like to use a script instead so that I can better control when this validation will be performed.

Thanks!!

Marc

1 Accepted Solution

Avatar

Correct answer by
Employee

Marc:

If your field has a display picture clause, then you can detect if it formatted correctly by looking at field.formattedValue

Specifically, if the value cannot be formatted, the formattedValue will be the same as the rawValue (unformatted).

So a validation script that specifies:

this.formattedValue !== this.rawValue;

should detect invalid dates.

See: http://blogs.adobe.com/formfeed/2011/06/understanding-field-values.html

good luck

  John

View solution in original post

2 Replies

Avatar

Correct answer by
Employee

Marc:

If your field has a display picture clause, then you can detect if it formatted correctly by looking at field.formattedValue

Specifically, if the value cannot be formatted, the formattedValue will be the same as the rawValue (unformatted).

So a validation script that specifies:

this.formattedValue !== this.rawValue;

should detect invalid dates.

See: http://blogs.adobe.com/formfeed/2011/06/understanding-field-values.html

good luck

  John