Question
I would like to be able to use a single regex (if possible) to require that a string fits [A-Za-z0-9_]
but doesn't allow:
- Strings containing just numbers or/and symbols.
- Strings starting or ending with symbols
- Multiple symbols next to eachother
Valid
test_0123
t0e1s2t3
0123_test
te0_s1t23
t_t
Invalid
t__t
____
01230123
_0123
_test
_test123
test_
test123_
Reasons for the Rules
The purpose of this is to filter usernames for a website I'm working on. I've arrived at the rules for specific reasons.
Usernames with only numbers and/or symbols could cause problems with routing and database lookups. The route for
/users/#{id}
allowsid
to be either the user's id or user's name. So names and ids shouldn't be able to collide._test
looks wierd and I don't believe it's valid subdomain i.e._test.example.com
I don't like the look of
t__t
as a subdomain. i.e.t__t.example.com