JavaScript Judging whether the input is a digital type method summary

JavaScript judges whether the input is a digital type method summary

Many times you need to judge whether an input is a bit number, simple below Enumerate the concentration method.

The first method isnan ISNAN returns a boolean value, indicating whether the value provided is a reserved value NaN (not a number).



 However, if NumValue is an empty string or a space, the IsNan is a number 0 for processing, and PARSEINT is back to an error message, which is not strict and caused by this ISNAN check.   The second method regular expression 

function checkrate (Input) {var RE = / ^ [0-9] +.? [0-9] * /; // Judgment whether the string is digital // Judgment positive integer / [1-9] + [0-9] *] * / if (! Re.test (nubmer)) {Alert (“Please enter a number”);}}

The third method utilizes the return value of PARSEFLOAT
   
Function isnotanumber (InputData) {// isnan (InputData) can not judge the empty string or a space // If it is a null string or a space, but isnan is doingTreated for numbers 0, and PARSEINT and PARSEFLOAT are returning an error message, which is not strict. IF (Parsefloat (InputData) .tostring () == “Nan”) {// alert (“Please enter the number …”); return false;} else {return true;}}

If you have any questions, please leave a message or to this site community to exchange discussions, thank you for reading, I hope to help everyone through this article, thank you for your support of this site!

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment