XF 2.1 REGEX Username Validation

Atmazphere

Member
Hi,

I'm looking to disable spaces in usernames, UTF codes, from being able to register on my forum.

So basically, letters and numbers only, how do I do this?
 

AndyB

Well-known member
Hi,

I'm looking to disable spaces in usernames, UTF codes, from being able to register on my forum.

So basically, letters and numbers only, how do I do this?

Here you go:

#^[a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[a-z][a-zA-Z0-9]*$#i

This regex code will not allow spaces and just a number. It requires minimum of two alpha characters.
 
Last edited:

Lukas W.

Well-known member
Not sure why you would add uppercase and lowercase variants on a case insensitive regex...


To limit usernames to the modern English alphabet, numbers and underscores:
Code:
/^\w+$/

Modern English alphabet, numbers, underscores and whitespace:
Code:
/^[\w ]+$/

Modern English alphabet and numbers:
Code:
/^[a-z0-9]+$/i

Modern English alphabet, numbers and whitespace:
Code:
/^[a-z0-9 ]+$/i
 

deslocotoco

Well-known member
How i permit the use too of á, à, ç, ã and that kind of characters and just letters, numbers, underlines and space?

Since my language is brazilian, i need the ' ´ ` ~ ç etc.
 

gldtn

Well-known member
How i permit the use too of á, à, ç, ã and that kind of characters and just letters, numbers, underlines and space?

Since my language is brazilian, i need the ' ´ ` ~ ç etc.
I'm using /^[a-z0-9À-ÿ_\-\ ]+$/i

a-z any letter
0-9 any digits/numbers
À-ÿ special characters (diacritics)
_ underscore
\-\ hyphen

and space for spacing.

Seems to work on the names I tested. If anyone that understand regex see anything wrong please let us know.
 
Last edited:

deslocotoco

Well-known member
I'm using /^[a-z0-9À-ÿ_\-\ ]+$/i

a-z any letter
0-9 any digits/numbers
À-ÿ special characters
_ underscore
\-\ hyphen

and space for spacing.

Seems to work on the names I tested. If anyone that understand regex see anything wrong please let us know.
Oh!

Thank you very much. I really need this. I cannot see non-ocidental letters in the nicks any more oh my board.

Deploying live now and i will keep you inform.

Update: The code /^[a-z0-9À-ÿ_\-\ ]+$/i is working perfectly for me. No errors and no more strange characters in the nicks of my board. Any administrator who runs a forum with Latin-based language should use this.

Thanks again!
 
Last edited:
Top