Is there a way to invoke pattern validation in script? or check if the field passes pattern validation?
The reasoning behind it is to avoid writing validation script which essentially does the same thing as parrtern validation.
If you are using validation patterns and the no pattern matched the entered data then the formattedValue will equal the rawValue. If the pattern was matched then the rawValue will be the canonical format, which for a date is YYYY-MM-DD, time is HH[MM[SS[.FFF][z]]], ...
So if your field is a text field you probably still have a problem. So for things like a phone number or email I haven't been using a pattern and validate the field with a regex in the exit event.
Any form node (Text Field, Drop-down List, etc) has a method you can invoke called "execValidate". This method invokes both the pattern and the script validation for the given node - in that order. If you had a form with a text field entitled txtTest for which you would like to run the pattern validation on, you would simply type:
Please let me know if you have any questions!
Cardinal Solutions Group
Thanks for your reply.
I know execValidate() invokes validation. But is there a way to know if the field passed the validation test after the call?
My question was if there's a way to know it.
this.mandatory = "";
xfa.host.messageBox("The entered date is invalid. Manually-entered valid date formats are as follows:\n\n- -YYYY-MM-DD\n- YYYY-M-D\n- YYYY-MM-D\n- YYYY-M-DD");
this.rawValue = "";
this.mandatory = "error";
The lines which set "mandatory" to "" and "error" respectively are there as a workaround to prevent the PDF from displaying a second dialog box complaining about a required field being empty. This is caused by line 3 within the if block where we clear out the rawValue. If the field you're validating is not a required field, you can omit those two lines.