Last active
March 17, 2016 09:25
-
-
Save ssskip/4ccbce396364b92da1e2 to your computer and use it in GitHub Desktop.
form validation
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
angular.module("kp.account") | |
/** | |
* @ngdoc directive | |
* @name kp.account.directive:kpNicknameValidation | |
* @description | |
* Defines validNickname method. | |
* length between 5-20,less than 5 digit numbers | |
*/ | |
.directive("kpNicknameValidation", function() { | |
return { | |
require: 'ngModel', | |
link: function(scope, ele, attr, ctrl) { | |
ctrl.$validators.validNickname = function(modelValue, viewValue) { | |
//required | |
if (!viewValue) { | |
return false; | |
} | |
var length = viewValue.length; | |
//length between 5-20 | |
if (length > 20 || length < 5) { | |
return false; | |
} | |
//less than 5 digit numbers | |
var matched = viewValue.match(/[0-9]/g); | |
if (matched !== null && matched.length > 5) { | |
return false; | |
} | |
return true; | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment