Add Validation for Registration Name Field

I'm trying to add a validation rule to the registration name field. I've added in my validation.js file a function like:

this.setHandler('name',
function (value) {
regex=/^\S[\S ]{2,98}\S$/;
return regex.test(value);
}
);

In registration.xml (components/com_users/models/forms/), I have added to the name field:

class="validate-name"
validate="name"

But it's still not validating against the rule. What am I doing wrong?

Answers


what are the properties of your registrationfield? At the first look of your regex I think minimum 2chars, maximum 98. And you can add any symbol except whitespaces?

If I were you, I would set my registration field (if on username) to \w\S{4,} \w is handy since it covers the expression [a-zA-Z_0-9] and if you add \S to it it covers the white space problem. Also, why you use the "\S" on the beginning and the end of your expression is a little blurry to me.

Hope this helped ;)

P.S.: If you like a nice tool to practice/test your regex, I can recommand Regex Designer. It's freeware and ez to use. Also, it gives you a lot of extra info on all kinds of different expressions


Need Your Help

Gnuplot: Creating Datasets using the Keyboard

keyboard dataset gnuplot

I need to color my data in two colors. So I'm using the 'index' property to define the linestyle of each dataset.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.