0

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?

theoth
  • 127
  • 3
  • 11

2 Answers2

1

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

finxie
  • 124
  • 2
  • 13
  • Hi, the property of the field is ` ` however the problem is not really the regex, its getting the regex to "hook" onto the field. Thanks for the advice on the regex freeware ;), I'll check it out. Do you know what I'm doing wrong for the field to not validate according to the regex though? – theoth Apr 06 '12 at 22:48
  • why do you use a `` ? why not just use `
    `? you should read [this article][1]. I know it looks very basic But it still does the trick ^^ [1]: http://docs.joomla.org/Client-side_form_validation
    – finxie Apr 07 '12 at 20:03
  • This isn't my own form though. This is the standard joomla registration field ;), I am simply trying to add a validation rule to the name field. Just like the email, username and password fields. – theoth Apr 07 '12 at 21:57
0

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

theoth
  • 127
  • 3
  • 11