mrcoulson
asked on
How can I make this regular expression case insensitive?
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])?
use RegexOptions.IgnoreCase option.
ASKER
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" />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Lord, I need to read a book on regular expressions. Let me try those!
Jeremy
Jeremy
ASKER
Both of those evaluate false.
Show me the test string.
ASKER
Wait a second. It could be that I wasn't paying attention and pasted them into the wrong document. Der.
Jeremy
Jeremy
ASKER
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.
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/
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/
mrcoulson, is there anything else I can provide regarding the solution?
ASKER
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
Thanks!
Jeremy
ASKER
Thanks a ton!
If you are serious about learning more you might consider finding a copy of the definitive reference text on the subject:
http://regex.info/
http://regex.info/
Thanks for the question and the points.