In this article, we will write a JavaScript function to validate whether a given value is a number or not.

To validate a value, is a number or not , we will use the isNaN() method.

Demo : check if character is a number. #
function myFunction(e){
  if(!isNaN(e)){
    return 'Yes, this is a number'
  }
  else{
    return 'No, this is not a number'
  }
}
Try it Yourself »

The isNaN() method returns true if the value is not a number. If the value is a number , it returns false.

Example : isNaN() method. # Try it Yourself »