Z
Z
ZaxapKramer2016-04-20 13:50:19
Regular Expressions
ZaxapKramer, 2016-04-20 13:50:19

What characters are allowed in the login (username)?

There are 2 options:

// Буквы латинского алфавита и цифры:
$regex_name1 = '/^[a-zA-Z0-9]+$/';
// Все, что в первом варианте, дефис (-), точка (.), знак нижнего подчеркивания (_):
$regex_name2 = '/^[a-zA-Z0-9-._]+$/';

There is also a 3rd option - the second option, in which the login cannot begin with a sign (hyphen, dot or underscore), and more than 2 characters in a row cannot be used:
$regex_name3 = '/^(?![_.])(?!.*[-_.]{2})[a-zA-Z0-9-._]+(?<![-_.])$/';

I lean more towards the first option, but I think that it is very limited. The third option is an improved second one, but it is easy and simple to convey it to the user (without forcing him to read at least 1 line of text during registration) - this is irrational.
I want to hear your opinion on this matter. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
trevoga_su, 2016-04-20
@ZaxapKramer

xpoint.ru/forums/programming/theory_algorythms/thr...
xpoint.ru/forums/internet/theory/thread/22534.xhtml
there is no standard for this. the emphasis in any checks is on the fact that the user would not enter a login/password in the style ^vasya_$123#*& and then forget their logins/passwords.
the standard alphabet a-z0-9 with a couple of characters to separate (- or _) will be enough for many millions of users.

X
xmoonlight, 2016-04-20
@xmoonlight

$regex_name4 = '/^[a-zA-Z0-9-_]{3,20}$/';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question