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.

4
  • Possible duplicate of How to validate an IP in a text field AngularJS Commented Feb 1, 2016 at 14:45
  • Thanks, But it is for only one IP address. My scenario we can input multiple IP addresses or IP ranges with comma separated Commented Feb 1, 2016 at 14:48
  • Don't delete one question just to ask the same one again an hour later Commented Feb 1, 2016 at 14:50
  • sorry for that. I thought it did not explain much Commented Feb 1, 2016 at 14:54

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. But it does not work for some scenarios like ; (5.55.55.555 , 4.4.4.4 )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.