?
Solved

Meaning of this regular expression

Posted on 2012-08-28
3
Medium Priority
?
437 Views
Last Modified: 2012-08-30
i want to  this regular expression  for usernames and email validation. What's the meaning of it?

^[^\s+.@-]+([-+.][^\s+.@-]+)*@[^\s+.@-]+([-.][^\s+.@-]+)*\.[^\s+.@-]+([-.][^\s+.@-]+)*$"

takes @, uppercase, lowercase, numbers, special characters?
0
Comment
Question by:Camillia
  • 2
3 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38343760
^           -  Start of string
[^\s+.@-]+  - One or more ( + ) of any character NOT ( [^ ... ] ) a whitespace character (tab, space, newline, etc.), a plus symbol, a period, an "at" symbol or a hyphen
(           - Start of capture group 1
[-+.]       - Either a hyphen, a plus or a period (only one)
[^\s+.@-]+  - One or more ( + ) of any character NOT ( [^ ... ] ) a whitespace character (tab, space, newline, etc.), a plus symbol, a period, an "at" symbol or a hyphen
)           - End of capture group 1
*           - Zero or more of the thing to the right; in this case, all of capture group 1 (meaning the whole of capture group 1 can repeat
@           - Literal @
[^\s+.@-]+  - One or more ( + ) of any character NOT ( [^ ... ] ) a whitespace character (tab, space, newline, etc.), a plus symbol, a period, an "at" symbol or a hyphen
(           - Start of capture group 2
[-.]        - Either a hyphen or a period (only one)
[^\s+.@-]+  - One or more ( + ) of any character NOT ( [^ ... ] ) a whitespace character (tab, space, newline, etc.), a plus symbol, a period, an "at" symbol or a hyphen
)           - End of capture group 2
\.          - Literal period
[^\s+.@-]+  - One or more ( + ) of any character NOT ( [^ ... ] ) a whitespace character (tab, space, newline, etc.), a plus symbol, a period, an "at" symbol or a hyphen
(           - Start of capture group 3
[-.]        - Either a hyphen or a period (only one)
[^\s+.@-]+  - One or more ( + ) of any character NOT ( [^ ... ] ) a whitespace character (tab, space, newline, etc.), a plus symbol, a period, an "at" symbol or a hyphen
)           - End of capture group 3
*           - Zero or more of the thing to the right; in this case, all of capture group 3 (meaning the whole of capture group 3 can repeat
$           - End of string
"           - Literal quote -- but I think this is just a copy/paste error from when you input the pattern into your question

Open in new window


You could use that pattern for email verification, but it does accept quite a few non-email characters as well (namely the control characters--ASCII 0 - 31).
0
 
LVL 7

Author Comment

by:Camillia
ID: 38343774
anyway to exclude ASCII 0 - 31 ?
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38343998
Change each "[^\s+.@-]" to "[^\s+.@\x0-\x1F-]".
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question