• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

Regular expression to allow dashes in email

Please any one cam tell me how allow the follwing regular expression to allow the dashes(-) in email and also explain the regular expression  for email
I am very poor to understand regular expression for email
in my project it is say like this (this should be modified to allow dashes)
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

Thanks in Advance
Latha
0
LathaLiquidHub
Asked:
LathaLiquidHub
  • 8
  • 7
1 Solution
 
HonorGodCommented:
Does this help?
\w+              = 1 or more "word" characters (letters, digits, or underscore)
([-+.']\w+)*     = 0 or more of
                     Exactly 1 of: a dash, plus, period, or single quote,
                     immediately followed by
                     1 or more "word" characters
@                = An at sign
\w+              = 1 or more "word" characters (letters, digits, or underscore)
([-.]\w+)*       = 0 or more of
                     Exactly 1 of: a dash, or period,
                     immediately followed by
                     1 or more "word" characters
\.               = A period
\w+              = 1 or more "word" characters (letters, digits, or underscore)
([-.]\w+)*       = 0 or more of
                     Exactly 1 of: a dash, or period,
                     immediately followed by
                     1 or more "word" characters

Open in new window

0
 
HonorGodCommented:
So, the reason that the RegExp allows a dash (hyphen) is because of this part of the RegExp:

[-+.']

Which is the RegExp way of saying "pick exactly 1 of the listed characters"
0
 
LathaLiquidHubAuthor Commented:
It great I understood very well

Thanks a Lot

Latha
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LathaLiquidHubAuthor Commented:
/([\w-+\.]+)@((?:[\w-]+\.)+)([a-zA-Z]{2,4})/

Please Explain this also

Is this allow dashes(-) ?


Thanks
Latha
0
 
HonorGodCommented:
Depending upon the programming language being used, a RegExp can be within quotes, or delimited (started, and ended) with '/'




Thanks for the grade & points.

Good luck & have a great day.
/                 = Starting delimiter
([\w-+\.]+)       = Group #1 containing 1 or more instances of:
                    \w = a word character
                    -  = This "might" be a hyphen, depending upon the RegExp Engine
                         If you really want a dash/hyphen to be allowed, it is best
                         to either begin, or end the list of "characters" within a
                         class (i.e., within square brackets) with a dash/hyphen
                    +  = A plus sign
                    \. = a period
@                 = An at sign
(                 = Group #2, containing
  (?:[\w-]+\.)+)  = 1 or more instances of a non-capturing group containing
                    []+  = 1 or more of:
                      \w = Word characters
                      -  = minus sign/dash/hyphen
                    \.   = followed by a period
  (               = Begin Group #3 - the closing parenthesis is missing!
    [a-zA-Z]{2,4} = Exactly 2 to 4 upper, or lowercase letters
                  < I suspect that this is where the Group #3 closing parenthesis should go
)                 = End of Group #2
/                 = Ending delimiter

Open in new window

0
 
HonorGodCommented:
So to answer your question:

Q: Does it allow dashes?
A: Not in its current form, it is a syntactically invalid RegExp.

  If you were to correct the RegExp by adding a closing parenthesis in the specified place:

And put the dash in the first group at the beginning of the class, then dashes would be allowed before and after the @ sign, but not in the last 2-4 letters
/([-\w+\.]+)@((?:[\w-]+\.)+)([a-zA-Z]{2,4}))/

Open in new window

0
 
LathaLiquidHubAuthor Commented:
Thanks  A lot
Its great
Really a beatiful explanation

Latha
0
 
LathaLiquidHubAuthor Commented:
/([-\w+\.]+)@((?:[\w-]+\.)+)([a-zA-Z]{2,4}))/

No of parenthses are differing opening four and closing are 5 is this effects ?
0
 
HonorGodCommented:
Let's see:
/([-\w+\.]+)@((?:[\w-]+\.)+)([a-zA-Z]{2,4}))/ 
 |         | ||          | ||             ||
 +---------+ |+----------+ |+-------------+|
             +-------------+               |
                                           +--- Unmatched, I was wrong

Open in new window

0
 
LathaLiquidHubAuthor Commented:
Thank you
Can I remove the unmatched one and use the expression?

Latha
0
 
HonorGodCommented:
Yes, just remove it (i.e., the last one)
0
 
LathaLiquidHubAuthor Commented:
Hi HonorGod,

Could you please answer for question  
Id is  ID: 26971892

since one month i geting this error while deploying the WSP

Thanks in advance

Latha
0
 
HonorGodCommented:
I'm sorry. Latha, about what question are you talking / asking?  If the question is this one, restate it please.  If it is another question, please provide a link.

Thanks
0
 
LathaLiquidHubAuthor Commented:
0
 
HonorGodCommented:
Sorry, I'm unfamiliar with wsp.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now