Jump to content

RegEx Expanded email check, pitfalls?


The Letter E

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/230739-regex-expanded-email-check-pitfalls/
Share on other sites

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)/ .

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.