I am a newbie for jquery and currently have a problem on jquery validation. Here is my codes:
jQuery(function(){
jQuery("#qty").validate({
expression: "if (VAL) return true; else return false;",
message: "please enter buying amount"
});
jQuery("#qty").validate({
expression: "if (!isNaN(VAL)) return true; else return false;",
message: "Only integer is valid for amount"
});
jQuery("#qty").validate({
expression: "if (VAL > 0) return true; else return false;",
message: "At least buy 1 share"
});
jQuery("#qty").validate({
expression: "if (VAL <= jQuery('#division').val()) return true; else return false;",
message: "You have insufficient amount to purchase"
});
and another relevant part:
<td><input type="text" name="quantity" size="10" id="qty" value=""/>
<?php
$division = $available/$rate;
?>
Now the problem is I cannot detect whether the quantity input is decimal. If it is decimal, I want to show error message: only integer is valid for amount. And also, when I compare the quantity input to $division, no matter what positive integer I enter, it will always show the error message “you have insufficient amount to purchase”. Can anyone give me some advice? Say thank you in advance!
You can use this methodology to know the number is not decimal
and in terms of comparison parse the value in to Int i.e.
and to prevent leading 0 you could use