0

I want to validate IP Address.

My html page code is given below

<md-content class="md-padding" ng-controller="AddNewHostController as vm">
    <form name="hostForm" ng-submit="vm.AddNewHost(hostForm.$valid)" novalidate>
        <md-content md-theme="dark" class="md-padding" layout="row" layout-sm="column">
            <md-input-container>
                <input ng-model="vm.host.hostname" required placeholder="Hostame">
            </md-input-container>
            <md-input-container>
                <input ng-model="vm.host.ipaddress" required placeholder="IP Address" ng-pattern="/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/">
            </md-input-container>
            <div ng-show="hostForm.$submitted || vm.host.ipaddress.$touched">
                <span ng-show="vm.host.ipaddress.$error.pattern">Invalid input</span>
            </div>
            <md-input-container>
                <input ng-model="vm.host.alias" required placeholder="Alias">
            </md-input-container>
        </md-content>
        <md-content class="md-padding">
            <button class="md-button md-ink-ripple" style="background-color:#7ec9c2; height: 12px; margin-left: 0px;">Add New Host</button>
        </md-content>
    </form>
</md-content>

But my ng-pattern not working. On button click I did not get Invalid input error message.

user3441151
  • 1,880
  • 6
  • 35
  • 79
  • 1
    Reduce the problem to the core: you have a regular expression and it does not match some input. Please add examples where it does match and where it doesn't. Please also use one of the 231 online regexp tools to analyze your expression. – reto Jan 10 '17 at 07:23
  • https://www.debuggex.com/ is very useful to validate reg exp patterns – Mr_Perfect Jan 10 '17 at 07:31
  • @reto I follow http://stackoverflow.com/questions/25548351/how-to-validate-an-ip-in-a-text-field-angularjs – user3441151 Jan 10 '17 at 08:34

0 Answers0