Expand my Community achievements bar.

Validating Numeric Values

Avatar

Former Community Member
Hai,



Suppose if there is a month field and want to restrict the value not more then 12. Could any one of you please help me in this regard by mean of setting any property or wirting any simple FormCalc code.
6 Replies

Avatar

Former Community Member
You can have a drop down list that contains values for selecting from 1 to 12 or Jan to Dec. This way, the user can only select what is given.

Avatar

Former Community Member
Hai,



Thanks for your reply.



But the requirement is such that only text field should be used.



Please let me know how to achieve using only the text field.



Thanks in advance.

Avatar

Former Community Member
It makes more sense to use the numeric field rather than text field for month since you enter a numeric value for the month.



You can put below javascript on the exit event of the month field.



if ((NumbericField1.rawValue > 12) || (NumericField1.rawValue < 1) || (NumbericField1.rawValue == null))

{

app.alert("You should enter a month and it should be from 1 to 12.");

xfa.host.setFocus("NumericField1");

}

Avatar

Former Community Member
Hi,



I'm quite new at Adobe Livecyle Designer and I'm having little difficulties with the validation technique proposed by jimmypham.



It works perfectly for the "month" field, but if I use the same validation technique on 2 adjacent fields I have a problem. If I enter "20" in the "Month" field and tab to get to the "Day" field, I get the error message. But when I click "OK", I immediately the error message for the "Day" field also. When I click "OK", the "Month" error message comes back again and it becomes a loop that I can't get out of.



Can anyone help?

Avatar

Former Community Member
Francois,



There are more traditional ways to validate data entered on a form. What jimmypham proposed is certainly valid but it can get you into trouble because it attempts to set the input focus back to the field containing the error.



If this isn't a requirement, then I suggest you use simple validation scripts on each of the month, day and year fields (I'm assuming the "2 adjacent field" are the day and year fields) and set each field's Type property (on the Object palette's Value tab) as
User Entered - Required so that the form can't be submitted without those values entered correctly.



On the month field's Validate event (use the Script Editor palette to edit a field's script), you could use the following JavaScript:



this.rawValue != null && this.rawValue >= 1 && this.rawValue <= 12


This will show an error message if the month entered is not between 1 and 12. On the day field's Validate event, the following JavaScript:



this.rawValue != null && this.rawValue >= 1 && this.rawValue <= 31


And on the year field's validate event, the following JavaScript:



this.rawValue != null && this.rawValue >= 1900


Finally, you can specify the validation error message that Acrobat displays by setting each field's Validation Script Message property on the Object palette's Value tab.



I've attached a sample form which has 3 fields: month, day and year. Each field is required and has the pertaining validation script from above assigned to it as well as a Validation Script Message. The form also has an email submit button. If you try to submit the form when the data is incorrect, you'll get a message from Acrobat telling you that there are fields with incorrect data and therefore the form can't be submitted yet.



Stefan

Adobe Systems

Avatar

Former Community Member
Hello, I'm having the same issue with validation looping with consecutive fields needing to be validated. Stefan, your solution is much better since it doesn't allow for a loop to be generated, but it still allows a user to have incorrect input and to still print the form. Do you know of a solution that will incorporate a setFocus script so that the user cannot leave the field until it's filled correctly without generating a validation loop?



Thanks,

Dave