The aspNetEmail component uses this regular expression as its default check: [\w-]+@([\w-]+\.)+[\w-]+ There's a nice long regular expression from Jeffrey Friedl's Mastering Regular Expressions book towards the end of this module: http://search.cpan.org/src/MAURICE/Email-Valid-0.15/Valid.pm
Modification to the above: Instead of this: foreach (string part in parts) if (Byte.Parse(part) > 0xFF) return false; this will work fine too: foreach(string part in parts) Byte.Parse(part);
u have a expression validator ion the tool box just take it besides the textbox and just choose the expression emailidand control to validate to the textbox name and error in the error message thats it
I'm sure a whole thread could probably come from peoples preferred email validation regexps. Here's the one that I developed. It's in two parts ('cos I'm not good enough at RegExp to do it in one :)
It's a bit of a monster, but basically it allows 1 -
64 chars before the @ symbol, and a 5 - 255 char domain name, which I believe were the boundaries allowed by RFC 2822 (or 2821 I forget which and I'm not in the mood to look it up) The second part allows any number of strings of a..z;0..9 and some less popular
characters that are also valid (I'm not into discriminating on exoticness, that's up to the mail server administrator), delimited by "."s. Special characters aren't allowed in domain names (I think. I'm still not in a looking-it-up mood), and perhaps most
unusually, it allows addresses referenced by user@[ipaddress] because user@[123.456.789.012] is a valid address. I learned regexp specifically to address this problem and it gave me a whole day of head-aches to acheive it. I do hope someone else gets some
good use out of it. I've read of Jeff Friedl's solution but I've never seen it and I'm too cheap to buy the book. Does anyone know if his expression is worth the money?
NicButler
Participant
1885 Points
384 Posts
Email Address format validator function ( C# )
Jan 29, 2004 11:12 AM|LINK
private bool CheckEmail(string EmailAddress) { string strPattern = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$"; if ( System.Text.RegularExpressions.Regex.IsMatch(EmailAddress, strPattern) ) { return true; } return false; }RonAFS
Member
635 Points
127 Posts
Re: Email Address format validator function ( C# )
Feb 02, 2004 11:58 PM|LINK
alvin_cllim
Participant
795 Points
159 Posts
Re: Email Address format validator function ( C# )
Feb 18, 2004 12:40 AM|LINK
AmitTheNoob
Participant
881 Points
178 Posts
Re: Email Address format validator function ( C# )
Feb 18, 2004 01:38 AM|LINK
static bool IsValidIP(string ip) { string[] parts = ip.Split('.'); if (parts.Length != 4) return false; try { if (Byte.Parse(parts[0]) == 0x00) return false; foreach (string part in parts) if (Byte.Parse(part) > 0xFF) return false; } catch(Exception) { return false; } return true; }IMHO its much simpler than using a regexp. And I couldn't come up with the right regexp either ;)AmitTheNoob
Participant
881 Points
178 Posts
Re: Email Address format validator function ( C# )
Feb 18, 2004 09:05 PM|LINK
shivksingh
Member
27 Points
6 Posts
Re: Email Address format validator function ( C# )
Mar 09, 2004 03:14 PM|LINK
AmitTheNoob
Participant
881 Points
178 Posts
Re: Email Address format validator function ( C# )
Apr 24, 2004 12:35 AM|LINK
sabby
Member
5 Points
1 Post
Re: Email Address format validator function ( C# )
Dec 31, 2004 07:17 AM|LINK
vinaykumarkv
Member
20 Points
4 Posts
Re: Email Address format validator function ( C# )
Jan 04, 2005 11:08 AM|LINK
Wasted Charl...
Member
20 Points
4 Posts
Re: Email Address format validator function ( C# )
Feb 04, 2005 02:10 PM|LINK
filter1 = /^.{1,64}@.{5,255}$/ filter2 = /^([&'\=\?\+\^\{\}\~\w]+(\.?[&'\=\?\+\^\{\}\~\w]+)*)@(\[?)([A-Z0-9]+[-]?)+([A-Z0-9]+\.)+([A-Z]{2,4}|[0-9]{1,3})(\]?)$/iIt's a bit of a monster, but basically it allows 1 - 64 chars before the @ symbol, and a 5 - 255 char domain name, which I believe were the boundaries allowed by RFC 2822 (or 2821 I forget which and I'm not in the mood to look it up) The second part allows any number of strings of a..z;0..9 and some less popular characters that are also valid (I'm not into discriminating on exoticness, that's up to the mail server administrator), delimited by "."s. Special characters aren't allowed in domain names (I think. I'm still not in a looking-it-up mood), and perhaps most unusually, it allows addresses referenced by user@[ipaddress] because user@[123.456.789.012] is a valid address. I learned regexp specifically to address this problem and it gave me a whole day of head-aches to acheive it. I do hope someone else gets some good use out of it. I've read of Jeff Friedl's solution but I've never seen it and I'm too cheap to buy the book. Does anyone know if his expression is worth the money?