I have an input mask on my text box like
000,000,000.00
I have the following jQuery code to check the value of text box before submitting data.
var txt_box = $('#txt_box').attr('value');
if(txt_box <= 0 )
But now even if I didn't input any data, the box remains empty with only the input mask, data is submitting.
I have an input mask on my text box like
000,000,000.00
I have the following jQuery code to check the value of text box before submitting data.
var txt_box = $('#txt_box').attr('value');
if(txt_box <= 0 )
But now even if I didn't input any data, the box remains empty with only the input mask, data is submitting.
Share Improve this question edited Aug 3, 2010 at 11:14 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Jul 24, 2010 at 9:06 airair 6,26426 gold badges95 silver badges126 bronze badges 4- 18 what an amazing title – Greg Commented Jul 24, 2010 at 9:09
- 5 dear if u leave all this Criticism and reply to question, i should appricate this... – air Commented Jul 24, 2010 at 9:11
- 4 Yeah. Who downvotes this? It's a perfectly fine question. – Pekka Commented Jul 24, 2010 at 9:49
- 2 I fixed the spelling slightly, if it's not what you meant to say feel free to roll back. – Pekka Commented Jul 24, 2010 at 9:52
2 Answers
Reset to default 13First: Separating floating points with a dot notation
is required.
Second: You are checking for equal or less
not just less than
.
Third: Use parseInt()
or parseFloat()
to convert that input string into a Number
.
Example:
var txt_box = $('#txt_box').attr('value').replace(/,/g, ".");
if(parseFloat(txt_box) <= 0 )
You use <=
instead <
Anyway, you should parse value
to number too.