Typically data from ng-model biding from input is stored as a string. How can I check if user typed a number or not?
            Asked
            
        
        
            Active
            
        
            Viewed 368 times
        
    0
            
            
        - 
                    2Possible duplicate of [How to check if value is number](http://stackoverflow.com/questions/31558283/how-to-check-if-value-is-number) – Madhawa Priyashantha Nov 17 '16 at 11:39
3 Answers
3
            
            
        You can use the angular IsNumber feature,
 if (angular.isNumber(modelvar) {
 }
 
    
    
        Sajeetharan
        
- 216,225
- 63
- 350
- 396
0
            
            
        Add validation on the input to prevent anything but numbers,
Allow only numbers to be typed in a textbox 
Or better, use a validation engine to check inputs and show warning messages.
0
            
            
        You can use;
<input type="number">
To ensure that in the HTML it's a number, and to check in angular;
if(typeof(VARIABLE) != "number"){
    console.log("error, variable is not a number");
    return;
}
Hope it helps!
 
    
    
        Tom Johnson
        
- 679
- 5
- 15
 
     
    