0

I am using input type number in my html page but I don't want the numbers in e format . I am trying to use a regex like follows:

$scope.regexInteger = '^[0-9^e]*$';

and trying to invalidate it using ng-messages

<input type="number" maxlength="20" class="w3-input w3-border w3-round-large" ng-pattern="regexInteger" name = 'intVal' />
<div ng-messages='intVal' >
<div ng-message="pattern">Invalid Integer</div>
</div>

But I am not able to invalidate it using the ng-messages. I guess I am not passing the correct regex.

Please correct me where I went wrong.

Tarun
  • 271
  • 1
  • 6
  • 18
  • 1
    Try this regex: `/[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/` ([source](https://stackoverflow.com/questions/638565/parsing-scientific-notation-sensibly)) – Sebastien Servouze May 29 '18 at 07:47
  • Create a custom directory which only accept numbers. – Sudhir Ojha May 29 '18 at 07:51
  • This regex is not stopping the user to enter 'e'. – Tarun May 29 '18 at 07:51
  • What is it that you're trying to achieve by adding the `^e` inside the group? My guess is that you're trying to explicitly say "not the character 'e'", which makes sense, but you're getting that already implicitly with the `[0-9]`, which just says only accept characters between "0" and "9", i.e. only numeric characters. – DaveyDaveDave May 29 '18 at 12:38

1 Answers1

1

try this .. This would be a simple solution as you will be using regular expression which allows only numbers 0-9 and not any other characters

$scope.regexInteger ='^[0-9]*$'
Sravya Nagumalli
  • 718
  • 1
  • 6
  • 8