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
  • 1
  • 7

3 Answers3

3

You can use the angular IsNumber feature,

 if (angular.isNumber(modelvar) {
 }
Sajeetharan
  • 203,447
  • 57
  • 330
  • 376
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
  • 2,842
  • 6
  • 40
  • 71
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
  • 659
  • 5
  • 15