JavaScript Function to Check Whether User Input Float Number

JavaScript Function to Check Whether User Input Float Number

The function below will check the User Input , whether it is a float  and return a true Boolean

If the User enter a String or a integer Number it will return a false Boolean Value


function isCorrectFloat(input){
                                             var bit =false;
                                             var outtxt= "";

                                             // When the Input  receive will be  Convert to float
                                            // If it is a Number Conversion will be turn into Float if it is a String Conversion will be
                                           // Converted to NAN
                                            input = parseFloat(input);

                                          // So if it is a String it will be converted to NAN
                                          // Check whether the Value is NAN?

                                        if(isNaN(input)){

                                                              bit= false;

                                                                      }

                                         // If it is Not NAN
                                        else{
                                                     // Is a Number ?
                                                          if(typeof input=='number'){
                                                               // input Number equals type input and input modulas 1 not equal 0
                                                                 if(Number(input) === input && input % 1 !== 0){
                                                                                                               bit =true;
                                                                                                                                                                               }
                                                                                                      else{
                                                                                                                  bit =false;
                                                                                                            

                                                                                                               }


                                                                                                      }

                                                                                 }

                                                                  return bit;
                                                      }

JavaScript Resources

Leave a Comment

3 + twelve =