I have a form for user input quantity. The form has client-side validation to ensure that the value is an integer and within a given range. The action page has server-side validation to ensure that it is an integer and greater than zero.
However, one type of value passes the test and raises INSERT / UPDATE queries to throw exceptions. This value is an integer with a plus sign - i.e. "7+" or "12+".
When this value is entered, a ColdFusion-generated JavaScript check raises a JavaScript error:
_CF_checkformAddToCart = function(_CF_this) { //reset on submit _CF_error_exists = false; _CF_error_messages = new Array(); _CF_error_fields = new Object(); _CF_FirstErrorField = null; //form element itemQuantity 'INTEGER' validation checks if (!_CF_checkinteger(_CF_this['itemQuantity'].value, false)) { _CF_onError(_CF_this, "itemQuantity", _CF_this['itemQuantity'].value, "Error on itemQuantity, please enter an integer value for quantity that is not greater than 500"); _CF_error_exists = true; } //form element itemQuantity 'RANGE' validation checks if (!_CF_checkrange(_CF_this['itemQuantity'].value, 0.0,500.0, false)) { _CF_onError(_CF_this, "itemQuantity", _CF_this['itemQuantity'].value, "Error on itemQuantity, please enter an integer value for quantity that is not greater than 500"); _CF_error_exists = true; } }
As soon as I cancel the pop-up error message, it will go to the action page, where I [try to] check the value like this:
<cfif IsValid("integer", form.itemQuantity) AND form.itemQuantity GT 0> <cfquery> INSERT ....
However, if you try this ...
<cfset x = Int("7+") />
... ColdFusion gives an error message.
Is it an integer or not ColdFusion ???
How can I get around this and check the form input correctly?