Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Restricting a value in a numeric field to a range

Avatar

Level 4
Is there a way of restricting input into a numeric field to the range 1 to 7 with a single digit decimal? For instance the value 7.5 would be accepted but 8.0 or 10.5 would not.



I have set every conceivable combination -- Field data pattern to 9.9; Field data format to 9.9; and Binding data pattern to 9.9 with format to decimal. Even the Validation pattern 9.9 will allow entry of values outside of the requested pattern (it just prompts with the pattern but still leaves the incorrect value).



Is there a way of enforcing the pattern AND allowing the field to be left blank if no value is required?
5 Replies

Avatar

Level 5
Try to use script similar to following in 'Validation' event of the field. When failed it triggers validation error message to display.



(this.rawValue >= 1 && this.rawValue < 7.5);



this is JavaScript code.

Hope this works for you.



SekharN

Lawson Software.

Avatar

Level 10
Hi,



I tried the same: (this.rawValue >= -1 && this.rawValue <= 1); script in a numeric field. However while the validation script message came up if the value was outside the range, I found that when the User clicked OK they could leave the value (which was outside the range) in the field (effectively disregarding the warning - that's Users for you ;-)).



Is there a way to force the value inputed into the field to be within the range, i.e. reverting to -1 if the User inputed a negative number outside of the range or +1 if the User inputted a positive number outside the range?



Thanks in advance,



Niall

Avatar

Level 5
Niall,<br /> Past the following FormCalc code to 'exit' event of the field and this code allows only value of 0 through 9 and <null>. I think this code helps you.<br /><br />if ($.rawValue <> "") then<br /> if (($.rawValue <= -1) or ($.rawValue >= 10)) then<br /> xfa.host.messageBox("Please check the number. 0 through 9 is accepted.")<br /> //$.rawValue = ""<br /> xfa.host.setFocus($.somExpression)<br /> endif<br />endif<br /><br />SekharN<br />Lawson Software.

Avatar

Level 10
Excellent!! Thank you Sekhar, worked first time. :-)



Regards,



Niall

Avatar

Level 4
Thank you so very much.

I tried the FormCalc code and it worked perfectly!