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

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -