How to guide only permits registration of usernames with the first letter capitalized for XenForo

How to guide only permits registration of usernames with the first letter capitalized for XenForo

Thangvip9x

Active member
Thangvip9x submitted a new resource:

How to guide only permits registration of usernames with the first letter capitalized for XenForo - It only allows characters from a to z, digits from 0 to 9, hyphens, and dashes.

View attachment 303739

Hello everyone, today I will guide you on how to only allow registration with the first letter capitalized, followed by lowercase letters, hyphens, and dashes to prevent spam on your forum. To do this, you need to go to domain/admin.php?options/groups/usersAndRegistration, then find "Username match regular expression:" and enter
PHP:
/^[a-zA-Z][a-z0-9_-]+$/
as the pattern, then save it. That's it, you're done! Wishing you success, and don't...

Read more about this resource...
 
I have a doubt. How will the user know which characters are allowed and about this rule of the first letter being capitalized? Will there be any error messages?
 
I have a doubt. How will the user know which characters are allowed and about this rule of the first letter being capitalized? Will there be any error messages?
Don't worry, because real users know what to do to register, only automated bot registrations don't know that, and it will limit spam for your forum.
 
I run XF 2.3 and I tried this and I was still able to register with all small letters.
I actually logged out and created an account on my site with another browser and that was my result.
 
I run XF 2.3 and I tried this and I was still able to register with all small letters.
I actually logged out and created an account on my site with another browser and that was my result.
Oh, I allow both lowercase and uppercase letters, so you can register with lowercase letters as well.
 
How can I add accents?

Â, Á, Ã, Ê, É, Í, Ô, Õ, Ó, Ú, Ç
â, á, ã, ê, é, í, ô, õ, ó, ú, ç

I tried this code:

PHP:
/^[A-ZÂÁÃÊÉÍÔÕÓÚ][a-zA-Z0-9ÂÁÃÊÉÍÔÕÓÚÇâáãêéíôõóúç_-]+$/

But lowercase letters are still being allowed. (ângela)
 
Last edited:
How can I add accents?

Â, Á, Ã, Ê, É, Í, Ô, Õ, Ó, Ú, Ç
â, á, ã, ê, é, í, ô, õ, ó, ú, ç

I tried this code:

PHP:
/^[A-ZÂÁÃÊÉÍÔÕÓÚ][a-zA-Z0-9ÂÁÃÊÉÍÔÕÓÚÇâáãêéíôõóúç_-]+$/

But lowercase letters are still being allowed. (ângela)
Please try it

PHP:
/^[ÂÁÃÊÉÍÔÓÚÇA-Z][a-zÂáãêéíôóúç0-9_-]*$/

If it works as you expect, hit like!
 
Last edited:
Don't worry, because real users know what to do to register, only automated bot registrations don't know that, and it will limit spam for your forum.
Are you sure?
For example, at the moment 30% of members do not have a username starting with a capital... with your restriction they would had their registration refused without even knowing what is blocking.

1717829951169.webp
 
Are you sure?
For example, at the moment 30% of members do not have a username starting with a capital... with your restriction they would had their registration refused without even knowing what is blocking.

View attachment 303931
The code still applies to registered members with lowercase and uppercase initial letters, for example, "abcd" and "Abcd" are valid, but "abCd" or "abCD" are not valid.
 
If I want to register on a forum that applies your restriction with the username rocket my registration will be blocked, right? How is the user informed of what blocks his registration?
 
No, both "rocket" and "Rocket" are valid, but "roCKET" or "rOcket" are not valid. Users will receive a warning stating: "Please enter another name. The entered value does not match the required format."
 
Ah ok i understand now.
Maybe it's because of my level in English but the title of the resource makes me think that only users with a username starting with a capital were accepted. But precisely it is if the user wants a capital letter in his username then it is only allowed in the first character.
 
Ah ok i understand now.
Maybe it's because of my level in English but the title of the resource makes me think that only users with a username starting with a capital were accepted. But precisely it is if the user wants a capital letter in his username then it is only allowed in the first character.
Right, go ahead and hit like if it's helpful to you.
 
Please try it

PHP:
/^[ÂÁÃÊÉÍÔÓÚÇA-Z][a-zÂáãêéíôóúç0-9_-]*$/

If it works as you expect, hit like!
Yes, it's working, but I want to allow uppercase in other letters too, like, Mateus_Gamer. Antônio_Álvaro...

So I made with more letters another version:

PHP:
/^[ÂÁÊÉÍÔÓÚÇA-Z][a-zA-ZâãáêéíôõóúçÂÁÃÊÉÍÔÓÕÚÇ0-9_-]*$/

with all accent, but I don't know why, lowercase is allowed at the beginning. (I removed some accents at the beginning of the letter because, come to think of it, we don't have names starting with Ã, Õ, Ô. But I allowed the rest because someone might want to write their name in capital letters, like JOÃO.)
 
Back
Top Bottom