Garuuk
Garuuk

Reputation: 2254

regex pattern repetition and ng-invalid

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?

Upvotes: 1

Views: 108

Answers (1)

Filipe
Filipe

Reputation: 1808

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.

Upvotes: 2

Related Questions