How to check if input is a number and call a function accordingly?

前端 未结 3 1084
不知归路
不知归路 2021-01-24 08:30

I have my code below..I need to modify it so that the input is checked if it is number.If its not a number, then a message has to be displayed as follows \" please enter only no

3条回答
  •  自闭症患者
    2021-01-24 09:34

    You may try like this:

    if (!isNaN(parseFloat(obj)) && isFinite(obj);) 
      {
        compare();
      }
     else
      {
    
        alert("Please enter only numbers");
        return false;
      }
    

提交回复
热议问题