1

I have this pattern like so

<input name="ip" ng-pattern="/^http:\/\/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]{4,5}/" class="form-control full-width text-right" type="text" ng-model="resource.ip"/>

The last part {4,5} is at least 4 and no more than 5. But when I type more than 5 integers at the end the form doesn't change to ng-invalid

This works on http://www.regexr.com/

Any idea why my input is allowing more than 5 characters?

Garuuk
  • 2,153
  • 6
  • 30
  • 59

1 Answers1

2

Just add $ to define the match end.

^http:\/\/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]{4,5}$

From the Reference > Archors > end:

Matches the end of the string, or the end of a line if the multiline flag (m) is enabled. This matches a position, not a character.

Filipe
  • 1,788
  • 2
  • 13
  • 18