Skip to content

Instantly share code, notes, and snippets.

@AmrAbdulrahman
Created July 7, 2015 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmrAbdulrahman/f1849967f5e0aa15d4a1 to your computer and use it in GitHub Desktop.
Save AmrAbdulrahman/f1849967f5e0aa15d4a1 to your computer and use it in GitHub Desktop.
goog.provide('sgo.manager.directives.port');
sgo.manager.directives.port = function() {
function link(scope, element, attrs, ctrl) {
var minPortValue = 0,
maxPortValue = 65535;
function validate(value) {
var isValid = true;
if(value !== undefined) {
if(isNaN(value) === true) {
isValid = false;
} else {
var parsedValue = parseInt(value);
if(parsedValue < minPortValue || parsedValue > maxPortValue) {
isValid = false;
}
}
}
ctrl.$setValidity('port', isValid);
return value;
}
ctrl.$formatters.unshift(validate);
ctrl.$parsers.unshift(validate);
}
return {
restrict: 'A',
link: link,
require: 'ngModel'
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment