0

I want to validate a text input with ng-pattern directory in AngularJs. The text input can have multiple IP addresses and IP ranges with , (comma) separated.

for an example;

172.168.21.3, 172.168.45.3/8, 172.53.23.12

Can someone help me on this.

PoX
  • 1,229
  • 19
  • 32

1 Answers1

0

why not try something like this:

// controller
$scope.regex = /((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?),?)/g;

// markup
<input type="text" ng-model="ipAddress" ng-pattern="regex">

That regex should match an IP Address any number of times with a conditional comma on the end, I put together a small plnkr example.

paul trone
  • 702
  • 5
  • 10