Check Whether A Textbox Value Is Numeric Or String
Possible Duplicate: Is there a (built-in) way in JavaScript to check if a string is a valid number? i want to check whether a textbox contains a numeric value or a string using
Solution 1:
Update: Looking back at my own answer, I realise the problem with it. You can't compare with NaN
, you need to use isNaN
function:
var query=getquerystring();
if(isNaN(parseFloat(query))
{
alert("query is a string");
}
else{
alert("query is numeric");
}
Or, alternatively, you can use regex pattern matching to see if the string matches what it should.
Post a Comment for "Check Whether A Textbox Value Is Numeric Or String"