Question

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?

Was it helpful?

Solution 2

Solution to get the validation to work was to add aria-required="true" to the field.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top