Is there a way to force a letter as the first character in the username?

Started by thelostswede, July 29, 2013, 04:49:45 AM

Previous topic - Next topic

thelostswede

Is there a way to force the first character in a new users username to be a letter rather than say a special character? Numbers should be ok to have first I guess, but having people registering usernames like .... isn't so cool for example.
I've searched the forum, but I didn't come up with an answer to the question.

Cheers

MrPhil

There have been requests before to control the alphabet used in Screen Names (i.e. restrict it to ASCII). This would be a further restriction. I may have some code at home to do this, but I can't look until tonight.

MrPhil

See http://www.simplemachines.org/community/index.php?topic=497825.msg3493351#msg3493351 for restricting the character set to a subset of ASCII. Add an additional check to restrict the first character to letters:
if (preg_match('~[^A-Z0-9 _-]~i', $checkName)) {
becomes
if (preg_match('~[^A-Z0-9 _-]~i', $checkName) || preg_match('~[^A-Z]~i', $checkName[0])) {

The first preg_match should flag an error if any character not A-Z, a-z, 0-9, (space), _ or - is found in the name, and the second specifically checks the first character of the name for anything other than A-Z or a-z. Again, I haven't actually tried this, so let us know if it works for you. If it doesn't allow lowercase letters, change A-Z to A-Za-z and ~i' to ~' and see if that works.

If you don't care about any character but the first, you could remove the first preg_match( ) and the ||.



Advertisement: