Skip to content

Commit

Permalink
fix ip validation
Browse files Browse the repository at this point in the history
validation failed if value was null even if the field was not required.
now if the field is required use ng-required directive.
  • Loading branch information
geirkairam committed Oct 17, 2015
1 parent d5ffdce commit c07d3bf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/js/directives/ipv4Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ module.exports = function(app) {
require: 'ngModel',
link: function(scope, element, attributes, ngModel) {
ngModel.$validators.ipv4Address = function(modelValue) {
//validation for required should be done via ng-required directive
//or the validation even fails if the field is not required
if (typeof modelValue == 'undefined' || modelValue === '') {
return true;
}

// we run an additional regular expression against the model
// because the 'ip' module does not catch all cases
var ipRegex = /^(?:(?: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]?)$/;
Expand Down

0 comments on commit c07d3bf

Please sign in to comment.