The Letter E Posted March 15, 2011 Share Posted March 15, 2011 I'm trying to improve upon a standard regex that checks basic email syntax and add a restricted list of domain suffixes. i.e: .com, .net, .org etc... Is there any inherent problems any of you have come across that would make this method not worth while? Here's the regex: /^[a-zA-z0-9-._]+@[a-zA-Z0-9-]+\.(com|net|mobi|biz|org|us|edu)$/ As you can see instead of doing somthing like .{2,5} at the end or another length wildcard checker I've just compiled a list, that will eventually be a database driven solution, but for now it's still just concept. Is there anything similar to this and any improvement recommendations? Thanks in advance. E Quote Link to comment Share on other sites More sharing options...
mikecampbell Posted March 17, 2011 Share Posted March 17, 2011 http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains As you can see, there are a lot of top level domains. If performance is a serious issue, you might be able to optimize the regex by using something like this /(c(om|a|y|etc)|e(du|u|etc)|etc)/ instead of /(com|ca|cy|cetc|edu|eu|eetc|etc)/ . Quote Link to comment Share on other sites More sharing options...
The Letter E Posted March 17, 2011 Author Share Posted March 17, 2011 http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains As you can see, there are a lot of top level domains. If performance is a serious issue, you might be able to optimize the regex by using something like this /(c(om|a|y|etc)|e(du|u|etc)|etc)/ instead of /(com|ca|cy|cetc|edu|eu|eetc|etc)/ . Genius! That's a great suggestion. Thanks alot. Quote Link to comment Share on other sites More sharing options...
mikecampbell Posted March 17, 2011 Share Posted March 17, 2011 No prob. Of course if all you are doing is validating a single email, performance will not be an issue and you could use the simplified version you suggested (which will be easier to generate programmatically). Quote Link to comment Share on other sites More sharing options...
The Letter E Posted March 17, 2011 Author Share Posted March 17, 2011 No prob. Of course if all you are doing is validating a single email, performance will not be an issue and you could use the simplified version you suggested (which will be easier to generate programmatically). I'm definitely looking for a slightly more robust solution which you have made increasingly clear with your response. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.