jquery - validation if value is empty or zero ('0'), but what if it's "0.0" -
i encountered problem today when working on validating form. user has input price in price field. if input 0 (for reason) or leave empty, following code catches this:
var pricevar = $("#price").val(); if (pricevar == '' || pricevar == '0') { var errormessage = 'product price empty or zero. please enter above.'; $("#errordiv").html(errormessage).slidedown(); return false; } else { return false; }
my input field follows:
<input type="text" name="price" id="price" placeholder="0.00">
however, if (again, reason) user enters 0.00 isn't detected , form gets submitted. have tried null
, empty
nothing working. know how detect 0.00 empty number, 0.01 (or great) not?
you can use parsefloat()
convert variable string float, , should working.
if (parsefloat(pricevar) == 0) { // code }
Comments
Post a Comment