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

前端 未结 3 1091
不知归路
不知归路 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:21

    have you tried "typeof"?

    if ( typeof entered_num  === "number" ) {..} 
    else { //not a number }
    

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof

提交回复
热议问题