?
Solved

How can I make this regular expression case insensitive?

Posted on 2009-06-30
14
Medium Priority
?
719 Views
Last Modified: 2012-05-07
The regular expression below evaluates email addresses in my RegularExpressionValidator.  It is case-sensitive and only allows lowercase.  I would like it to allow uppercase as well.  I don't even understand how the thing works really, so I don't know where to begin modifying it.  How do I make it case-insensitive?
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

Open in new window

0
Comment
Question by:mrcoulson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
14 Comments
 
LVL 27

Expert Comment

by:ddrudik
ID: 24745705
use RegexOptions.IgnoreCase option.
0
 

Author Comment

by:mrcoulson
ID: 24745728
You may call me a lazy programmer, but this is all handled by a RegularExpressionValidator.
<asp:RegularExpressionValidator ID="vldSenderEmailFormat" runat="server" ControlToValidate="txtSenderEmail" ErrorMessage="Please enter a valid email address in the 'Your Email' field." ValidationExpression="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" Display="None" />

Open in new window

0
 
LVL 27

Accepted Solution

by:
ddrudik earned 2000 total points
ID: 24745758
You could also use:
[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?

or:
[\w!#$%&'*+/=?^`{|}~-]+(?:\.[\w!#$%&'*+/=?^`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mrcoulson
ID: 24745767
Lord, I need to read a book on regular expressions.  Let me try those!

Jeremy
0
 

Author Comment

by:mrcoulson
ID: 24745794
Both of those evaluate false.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24745800
Show me the test string.
0
 

Author Comment

by:mrcoulson
ID: 24745820
Wait a second.  It could be that I wasn't paying attention and pasted them into the wrong document.  Der.

Jeremy
0
 

Author Comment

by:mrcoulson
ID: 24745858
The first one seems to work.  Whew.  Could you go the extra mile and explain it a little to me?  Regular expressions look like massive sneezings of random characters and I'd like to understand them better.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24745980
I can only say that I added A-Z to the pattern in all places that you had a-z to make it case-insensitive.
I cannot say that the pattern actually will validate e-mail addresses (I would submit that validation of any/all e-mail addresses cannot be done with regex alone).

But, for some syntax starters:
[...] is a character set, any characters included within are treated as one set.
* is repeating 0 or more times.
+ is repeating 1 or more times.
. is any character
\ escapes any special characters such as . to make them match literally, such as \. would match "."
\w is a character class for [A-Za-z_]

I have a online regex tester here (PHP PCRE/.NET):
http://www.myregextester.com/

A cheatsheet:
http://regexlib.com/CheatSheet.aspx

Tutorials:
http://www.regular-expressions.info/
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24746730
mrcoulson, is there anything else I can provide regarding the solution?
0
 

Author Comment

by:mrcoulson
ID: 24746804
No, points are forthcoming.  I really appreciate the extra effort with the explanations.  I think I seriously need to do some studying in my downtime.

Thanks!

Jeremy
0
 

Author Closing Comment

by:mrcoulson
ID: 31598356
Thanks a ton!
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24746831
If you are serious about learning more you might consider finding a copy of the definitive reference text on the subject:
http://regex.info/
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24746832
Thanks for the question and the points.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

801 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