-1

I am new to Angularjs 1.6.. Project that i am currently working on needs to have a textbox validated only to enter numbers which currently works fine.. the issues is when i press letter "e" it doesn't work.. Please help me on this.. thanks.. here is my code..

<input
   type="number"
   class="form-control"
   name="days" 
   placeholder="Number of days"
   data-ng-model="$ctrl.my.scheduler"
   data-ng-pattern="/^[1-9]\d*$/;"
   required
>
Siya Mzam
  • 4,655
  • 1
  • 26
  • 44
Selaka Nanayakkara
  • 3,296
  • 1
  • 22
  • 42

1 Answers1

1

Technically speaking 'e' is a number, so you'll need a directive attached to the input to handle the validation. There is a SO post about this already, the first answer should provide what you need:

Prevent the letter 'e' and dots from being typed in an input number

rrd
  • 5,789
  • 3
  • 28
  • 36
  • How do you explain why the other characters do not pass then? Because they are also numbers, or at least backed up by some number. – Siya Mzam Nov 09 '17 at 07:59
  • Well you probably don't need the ng-pattern; if you have the filter added in you won't need it anyway. – rrd Nov 09 '17 at 08:05
  • You can do it without using a directive. As i posted below the answer below. its a matter of specifying the type of the input type of the textbox to text and rest will be handled by the regEx which you provide. If you set the input type as number it will accept letter "e" as number as it is technically. - @rrd – Selaka Nanayakkara Nov 10 '17 at 06:53