I have my java script in angular checking if the value of text field is undefined or empty, it is fine and working,
$scope.checkNumber = function(user_answer){
if(user_answer == undefined){
return false;
}
}
I have my java script in angular checking if the value of text field is undefined or empty, it is fine and working,
$scope.checkNumber = function(user_answer){
if(user_answer == undefined){
return false;
}
}
But my next step is how I can make a function to identify if the value has a string or a number and return a boolean. I don't know the right syntax for angular java script, can anyone help me to solve my problem?
Share Improve this question edited Feb 13, 2019 at 3:02 JustAce asked Jun 25, 2015 at 5:07 JustAceJustAce 2441 gold badge6 silver badges18 bronze badges 3- have you tried typeof , its inbuilt into JS – Sushant Commented Jun 25, 2015 at 5:21
- if you want to have a number only textfield, use <input type='number'> – Icycool Commented Jun 25, 2015 at 5:38
- @lcycool <input type='number'> doesn't prevent you from inputting strings – Robin-Hoodie Commented Jun 25, 2015 at 5:59
2 Answers
Reset to default 4You can do this the angular way, using the 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
}
}
Try like this
function check(text){
return typeof text ==="number";
}