|
-
Mar 12th, 2007, 03:24 PM
#1
[RESOLVED] Regular expressions - Username
I already have a function to check for a valid e-mail address using regular expressions, but I had written it awhile ago when I was still familiar with them.
Now I need one to check for a valid username. The username can only have letters, numbers, underscores (_), spaces, and a single period.
It has to start with a letter. It cannot have consecutive spaces (2 or more in a row).
Can someone help me?
-
Mar 12th, 2007, 05:49 PM
#2
Re: Regular expressions - Username
Something like
[a-zA-Z]([a-zA-Z0-9_]|( [a-zA-Z0-9_]))*(\.([a-zA-Z0-9_]|( [a-zA-Z0-9_]))*)?
In words: with a name character being an alphanumeric character or an underscore, a username is
an alphabetic character followed by
either a name character, or a space and a name character, repeated any number of times
followed optionally by
a dot and
either a name character, or a space and a name character, repeated any number of times
If you don't want to allow the dot as the last character, replace the last * by a +.
If you don't want to allow the dot as the last character and don't want a space to follow the dot, insert a name character collection after the dot, unconditionally.
As it is, the space character cannot be the last character, nor can it be directly before the dot.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 12th, 2007, 11:36 PM
#3
Re: Regular expressions - Username
 Originally Posted by CornedBee
Something like
[a-zA-Z]([a-zA-Z0-9_]|( [a-zA-Z0-9_]))*(\.([a-zA-Z0-9_]|( [a-zA-Z0-9_]))*)?
In words: with a name character being an alphanumeric character or an underscore, a username is
an alphabetic character followed by
either a name character, or a space and a name character, repeated any number of times
followed optionally by
a dot and
either a name character, or a space and a name character, repeated any number of times
If you don't want to allow the dot as the last character, replace the last * by a +.
If you don't want to allow the dot as the last character and don't want a space to follow the dot, insert a name character collection after the dot, unconditionally.
As it is, the space character cannot be the last character, nor can it be directly before the dot.
Wow thanks, that looks promising. I'll give it a try and report back. 
 Originally Posted by penagate
I hope you realise that properly validating email addresses using regular expressions is fairly abstruse. Simple validation is fine, but you invariably cut out 1% of potential addresses.
Wow. I'm not sure how well that would perform in PHP. Especially under high traffic. Shouldn't be too much of a problem, though. If they really want to register they'll use a different e-mail address. Thanks.
-
Mar 12th, 2007, 10:24 PM
#4
Re: Regular expressions - Username
I hope you realise that properly validating email addresses using regular expressions is fairly abstruse. Simple validation is fine, but you invariably cut out 1% of potential addresses.
-
Mar 23rd, 2007, 02:12 AM
#5
New Member
Re: [RESOLVED] Regular expressions - Username
cornedbee: wow this is good. can you pls modify it to not include white space characters? thanks, greatly appreciate it
or is this correct
[a-zA-Z]([a-zA-Z0-9_]|([a-zA-Z0-9_]))*(\\.([a-zA-Z0-9_]|([a-zA-Z0-9_]))*)?
Last edited by chitgoks; Mar 23rd, 2007 at 02:18 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|