开发者

Determine with jQuery validator that the value entered is NOT a number

My problem is very simple, but I can't find an equally simple solution. I have a text field that is validated via the jQuery validation plug开发者_如何学编程in, and I want to make sure that the value entered is NOT a number. What is the simplest way to do so? Thanks in advance! :)


I didn't work with jQuery validator yet, but I guess you can provide your own validation function.

You could do:

if(isNaN(+value)) {
    // not a number
}

Edit: Apparently, isNaN accepts a string too, so isNaN(value) suffices.

If you want to ensure that the input does not contain any digit (which is different from the input not being a number), then you would have to use regular expressions:

if(!(/\d/.test(value))) {
    // does not contain digits
}

P.S.: Also works without jQuery ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜