开发者

How do I handle this kind of condition in Javascript

开发者 https://www.devze.com 2023-02-02 00:43 出处:网络
I have a text field whichhas the regex validation and it should not accept value \"0\". whether I need to use \"and\" condition (or) \"OR CONDITION\" in the below if condition

I have a text field which has the regex validation and it should not accept value "0". whether I need to use "and" condition (or) "OR CONDITION" in the below if condition

var regex = /^[0-9][0-9]{0,3}$|^[0-9][0-9]{0,3}[\.开发者_如何学C][0-9]$/;
if(!regex.test($('#text1').val()))
{  
   alert("please ");     
}


If all you need to do is make sure the user didn't enter 0, couldn't you forego the regex and just do something like this?

var v = parseFloat($('#text1').val());
if (v == 0 ) {
  alert("please");
}
0

精彩评论

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