最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is 000,000,000.00 greater than zero? - Stack Overflow

programmeradmin9浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 13

First: 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.

发布评论

评论列表(0)

  1. 暂无评论