Skip to content

Commit

Permalink
Issue #14 validate subnet and v6prefix field
Browse files Browse the repository at this point in the history
  • Loading branch information
geirkairam committed Oct 18, 2015
1 parent 5ec9a2a commit 65a3a39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ <h2>
<input type="text" class="form-control" name="ipv6Prefix" id="ipv6Prefix"
placeholder="{{'ip.ipv6.placeholder' | translate}}"
data-ng-model="wizard.ip.v6Prefix"
data-ng-required="!state.ip.register">
data-ng-required="!state.ip.register"
data-ng-pattern="ipv6PrefixPattern">
<span style="" class="fa form-control-feedback" ng-class="{
'fa-times': hasError('ipv6Prefix'),
'fa-check': wizardForm.ipv6Prefix.$valid
Expand Down Expand Up @@ -621,7 +622,7 @@ <h2>
placeholder="{{'ip.distribute.subnet.placeholder' | translate}}"
data-ng-model="wizard.ip.v4ClientSubnet"
data-ng-required="wizard.ip.distribute && !state.ip.register"
data-ng-pattern="{{ipPattern + '/(25|26|27|28)'}}">
data-ng-pattern="ipv4Pattern+'\/(25|26|27|28)'">
<!-- TODO use ip npm package for validation -->
<span class="fa form-control-feedback" data-ng-class="{
'fa-times': hasError('ipv4ClientSubnet'),
Expand Down
12 changes: 11 additions & 1 deletion src/js/controllers/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,21 @@ module.exports = function(app) {
});
};

$scope.ipPattern = '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' +
$scope.ipv4Pattern = '(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]|2[0-4][0-9]|[01]?[0-9][0-9]?)' +
'\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';

//I really hate v6 regex patterns >:(

//http://home.deds.nl/~aeron/regex/
//$scope.ipv6Pattern = '((?=.*::)(?!.*::.+::)(::)?([\\dA-F]{1,4}:(:|ß\b)|){5}|([\\dA-F]{1,4}:){6})(((\[\dA-F]{1,4}((?!\\3)::|:\\b|$))|(?! \\2\\3)){2})';

//TODO more test and prefix addition
$scope.ipv6PrefixPattern = '((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*::((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*|((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4})){7}';

//http://regexlib.com/Search.aspx?k=ipv6&AspxAutoDetectCookieSupport=1

$scope.hasError = function(field) {
var form = $scope.wizardForm;
return (form.$submitted || form[field].$dirty) && form[field].$invalid;
Expand Down

0 comments on commit 65a3a39

Please sign in to comment.