我想提供验证条件,如
var BlkAccountIdV = $('#txtBlkAccountId').val();
if (BlkAccountIdV == "") {
document.getElementById('lblAccountId').innerText = "Enter Valid AccountID";
errorflag=1;
}
如果条件应该仅在输入文本框值包含Letter时执行。我可以在引号内给出什么值(if(BlkAccountIdV ==“”))?
答案 0 :(得分:2)
var re = /[^0-9]/g;
var error = re.test(BlkAccountIdV);
如果error
的值不是数字,则 BlkAccountIdV
将为true
即,这个正则表达式将匹配除数字之外的所有内容
所以你的代码看起来应该是这样的:
var BlkAccountIdV = $('#txtBlkAccountId').val();
var re = /[^0-9]/g;
if ( re.test(BlkAccountIdV) ){
// found a non-numeric value, handling error
document.getElementById('lblAccountId').innerText = "Enter Valid AccountID";
errorflag=1;
}
答案 1 :(得分:0)
if (BlkAccountIdV.match(/[0-9]+/) == null )
答案 2 :(得分:0)
在if条件下你可以使用isNaN()函数。这将检查字符串是否“不是数字”
因此,在您的情况下,如果此条件无效,则字符串为数字
if(!isNaN(BlkAccountIdV) && BlkAccountIdV != ''){
//Your code
}