Created
July 7, 2015 09:26
-
-
Save AmrAbdulrahman/f1849967f5e0aa15d4a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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