Solved

validate username using custom directives in angularjs

Posted on 2014-02-03
2
784 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 82

Accepted Solution

by:
leakim971 earned 500 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

825 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