Add Validation for Registration Name Field

Go To


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

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:


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

2012-04-04 21:12
by theoth


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

2012-04-13 12:42
by theoth


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

2012-04-06 14:57
by finxie
Hi, the property of the field is <field name="name" type="text" class="validate-fullname" description="COM_USERS_REGISTER_NAME_DESC" filter="string" label="COM_USERS_REGISTER_NAME_LABEL" message="COM_USERS_REGISTER_NAME_MESSAGE" required="true" size="30" validate="fullname" /> 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 2012-04-06 22:48
why do you use a <field /> ?
why not just use <form onSubmit=...><input /></form>? you should read this article. I know it looks very basic But it still does the trick ^ - finxie 2012-04-07 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 2012-04-07 21:57