0

Typically data from ng-model biding from input is stored as a string. How can I check if user typed a number or not?

A.New
  • 97
  • 2
  • 7

3 Answers3

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.

Community
  • 1
  • 1
Dabbas
  • 3,112
  • 7
  • 42
  • 75
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