DelphiFAQ Home Search:

Check if a user name contains non-alphanumeric characters

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

On my web site, a user may put in a desired user name and I have to check that it only contains letters, digits, or the @ and . characters. How can I do that with a regular expression (regex)?

Answer:

The allowed characters are described as A-Za-z0-9.
That are the intervals A-Z, a-z and 0-9. You can also substitute 0-9 with d (digit).

To check for the undesired character, use the ^ operator in front of it as shown below:

if ($username =~ /([^A-Za-z0-9@.])/) {
  print "Problem in user name with '$1'";
}


Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
Leave your comment here:
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.