简体   繁体   English

检查值的长度isnumeric jquery

[英]Check the length of value isnumeric jquery

Telephone: 电话:

if (!$.isNumeric($("#phone").val())) {

alert("error invalid number");

    }

I am making a simple form that allows the user to sign up but my problem is how to avoid the user should not click only 1 length of value. 我正在制作一个简单的表格,允许用户注册,但是我的问题是如何避免用户不应仅单击1个长度的值。 let I say the length should less than 7, I'll try to add && $("#phone").val().length < 7 in if statement. 我说长度应该小于7,我会尝试在&& $("#phone").val().length < 7语句中添加&& $("#phone").val().length < 7 but it wont work :( 但它不会工作:(

You are using an && when you need to use an ||. 当您需要使用||时,您正在使用&&。 If it is not numeric or it its length is less than 7. 如果不是数字或其长度小于7。

if (! $.isNumeric($("#phone").val()) || $("#phone").val().length < 7) {
    alert("Phone is not numeric");
}

You can check at this small jsfiddle 您可以在这个小jsfiddle上检查

http://jsfiddle.net/tsot1pt2/ http://jsfiddle.net/tsot1pt2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM