AngularJS验证IP地址的所有可能性

时间:2017-01-10 07:20:07

标签: angularjs

我想验证IP地址。

我的html页面代码如下所示

<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>

但我的ng-pattern无效。点击按钮后,我没有收到无效输入错误消息。

0 个答案:

没有答案