Answer: Use the jQuery. isNumeric() method You can use the jQuery $. isNumeric() method to check whether a value is numeric or a number. The $. isNumeric() returns true only if the argument is of type number, or if it's of type string and it can be coerced into finite numbers, otherwise it returns false .
In JavaScript, there are two ways to check if a variable is a number : isNaN() – Stands for “is Not a Number”, if variable is not a number, it return true, else return false. typeof – If variable is a number, it will returns a string named “number”.
count("$. value == '" + $(this). val() + "'") > 1) { // If more than 1 have the same value than highlight this textbox and display an error message $(this). addClass('duplicate'); $('#custom-field-validator').
isnan() isNaN() method returns true if a value is Not-a-Number. Number. isNaN() returns true if a number is Not-a-Number.
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
You've an number of options, depending on how you want to play it:
isNaN(val)
Returns true if val is not a number, false if it is. In your case, this is probably what you need.
isFinite(val)
Returns true if val, when cast to a String, is a number and it is not equal to +/- Infinity
/^\d+$/.test(val)
Returns true if val, when cast to a String, has only digits (probably not what you need).
there is a function called isNaN
it return true if it's (Not-a-number) , so u can check for a number this way
if(!isNaN(miscCharge))
{
//do some thing if it's a number
}else{
//do some thing if it's NOT a number
}
hope it works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With