Reputation: 949
i want to give validation condition like,
var BlkAccountIdV = $('#txtBlkAccountId').val();
if (BlkAccountIdV == "") {
document.getElementById('lblAccountId').innerText = "Enter Valid AccountID";
errorflag=1;
}
if condition should be Executed only when entered text box value contains Letter.What value can i give inside Quotation marks(if (BlkAccountIdV == "") )?
Upvotes: 1
Views: 18244
Reputation: 1304
var re = /[^0-9]/g;
var error = re.test(BlkAccountIdV);
error
will be true if value of BlkAccountIdV
is not numeric
I.e, this regex will match everything except numbers
So your code should look somehow like this:
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;
}
Upvotes: 2
Reputation: 1479
In if condition you can use isNaN() function. This checks whether string is 'not a number'
So in your case if this condition not valid, Then string is number
if(!isNaN(BlkAccountIdV) && BlkAccountIdV != ''){
//Your code
}
Upvotes: 0