How do I handle this kind of condition in Javascript
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");
}
精彩评论