?
Solved

validate username using custom directives in angularjs

Posted on 2014-02-03
2
Medium Priority
?
887 Views
Last Modified: 2014-02-05
Hi Experts ,

I have to validate username  (no special characters & digits)  across different forms / pages in AngularJS. So I want to create custom directive that can  be used at multiple forms/pages. I need sample working code using AngularJS.

Thanks in Advance
0
Comment
Question by:ksd123
2 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39831376
What about : http://jsfiddle.net/97ZRb/
you just need to add good-username in your username field

	App.directive("goodUsername", function() {
		return {
			require: "ngModel",
			restrict: "A",
			link: function(scope, el, attrs, ctrl) {
				ctrl.$parsers.unshift(function(viewValue) {
					var result = !/[^a-z0-9]/.test(viewValue);
					ctrl.$setValidity("goodUsername", result);
                    return viewValue;
				});
			}
		}
	});

Open in new window

0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39832048
Which criteria do you want to be applied to your username (es. only characters)?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question