简体   繁体   中英

angular/ui-mask ip address

I use angular/ui-mask in my project. Now I need a mask for block ip address range (example 192.168.70.18/20). For example:

 <input  ng-model="address" ui-mask="9?9?9.9?9?9.9?9?9.9?9?9/9?9" ui-mask-placeholder-char="_" placeholder="" ng-disabled="disabled">

The problem is so I can only enter this IP address: 192.168.125.254

jsFiddle: http://jsfiddle.net/Sheinar/Lvc0u55v/6133/

I think this solve your problem:

$scope.$watch('address', function (address) {
    if (!address || address.length < 15) return;

    var endFrom = parseInt(address.substr(9, 3)),
        endTo = parseInt(address.substr(12, 3));

    if (endFrom > endTo) {
        alert('invalida range');
        $scope.address = address.substr(0, 12);
    }
});

http://jsfiddle.net/matheusdev/Lvc0u55v/6144/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM