Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.