Regex to only allow numbers under 10 digits?

前端 未结 7 1671
暖寄归人
暖寄归人 2020-12-16 22:06

I\'m trying to write a regex to verify that an input is a pure, positive whole number (up to 10 digits, but I\'m applying that logic elsewhere).

Right now, this is t

相关标签:
7条回答
  • 2020-12-16 22:37

    You can do this way:

    /^[0-9]{1,10}$/
    

    Code:

    var tempVal = $('#targetMe').val();
    if (/^[0-9]{1,10}$/.test(+tempVal)) // OR if (/^[0-9]{1,10}$/.test(+tempVal) && tempVal.length<=10) 
      alert('we cool');
    else
      alert('we not');
    

    Refer LIVE DEMO

    0 讨论(0)
提交回复
热议问题