How can angularjs check if ng-model is string or number value?

I have a java script in angular, if the textbox value is undefined or empty, this is fine and it works,

$scope.checkNumber = function(user_answer){
	if(user_answer == undefined){
	  return false;					
	}
}
      

Run code


But my next question is how to make a function check if the value is a string or a number and returns a boolean. I don't know the correct syntax for the angular java script, can anyone help me solve my problem?

+3


source to share


2 answers


You can do it the angular way using angular helper functions:



$scope.checkNumber = function(user_answer){
    if(angular.isUndefined(user_answer)){
      return false;                 
    }
    if(angular.isString(user_answer)) {
       //return boolean
    }
    if(angular.isNumber(user_answer)) {
       //return boolean
    }
}

      

+3


source


try it



function check(text){     
 return typeof text ==="number";
}

      

+3


source







All Articles