Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

relearned how to write a regular expression for validating email addresses

Oct 19 2012 12:00AM by Paras Doshi   

I am working a Data Quality Services Demo where i had to figure out how to write a domain rule to validate a email address. for this task, i re-learned how to write a regular expression; here's my basic version: [A-Za-z0-9._-]+@[A-Za-z0-9.-]+.[A-Za-z] ; feel free to suggest edits!

Read More..   [32134 clicks]

Published under: General Technology Tips · Business Intelligence Tips ·  ·  · 


Paras Doshi
17 · 10% · 3265
9
 
2
 
 
0
Incorrect
 
0
Interesting
 
0
Forgotten



Submit

5  Comments  

  • What a coincidence! I too re-learnt about this yesterday at the office due to a business requirement! Thank-you for documenting it via this Just Learned item!

    commented on Oct 20 2012 2:06AM
    Nakul Vachhrajani
    4 · 36% · 11645
  • oh, is it? co-incidence indeed! :)

    commented on Oct 20 2012 1:45PM
    Paras Doshi
    17 · 10% · 3265
  • Using regex to validate email addresses is very difficult. The regular expression you presented does work in many cases but is very basic.

    One example is that + is a valid character in an email name. You are going to make a lot of gmail users mad if you don't accept it before the @ sign. If someone's email address is sql@gmail.com, he can submit to your site sql+beyondrelational@gmail.com and it will still arrive in his email box, but now he knows where the sender acquired his email address.

    Here is a bit more friendly one: \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b.

    But even that is not very complete. This will do a better job (please remove the line break):

    [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+
    [a-z0-9](?:[a-z0-9-]*[a-z0-9])?
    

    Second, you can to do a DNS lookup to see if an MX record exists for the given domain. That is the only way to get an inkling, without sending an email, of whether the domain is valid. But frankly, you can only know if an email address is truly valid by sending an email to it and seeing if it works. That is honestly the best practice. Why would you validate that an email has the correct format in preference to validating that the email in fact reaches the intended user?

    My final recommendation is to dispense with checking email addresses beyond the basic "it has an @ symbol and at least one dot afterward" and instead send an email-address-validation email to the darn thing. Then you know it's right, and at that point it doesn't even matter if it has Unicoded moon rocks in it. It works, so it's valid. If it wasn't right, the user will try again if he really wants to be part of your site. Do you have to have an email address anyway?

    (Note: if you like, read more on email regular expressions.)

    commented on Oct 21 2012 2:40AM
    ErikEckhardt
    65 · 3% · 898
  • Erik, I really like your 'unicoded moon rocks' expression!

    commented on Oct 22 2012 5:32AM
    dishdy
    16 · 10% · 3269
  • @Erik: Thanks, there's some great advice in there! I am going to switch to the regex that you suggested. And as you suggested, it would be best to just send a verification email. And you're right - this is very basic. I am developing a demo to show how you can use domain rules in Data Quality Services - But if it were not a demo, I would have also considered using reference data services like "email check data on datamarket.azure.com" to clean data. Thanks for taking time to share that, greatly appreciate your input.

    @dishdy: +1, I liked it too! :)

    commented on Oct 22 2012 10:53AM
    Paras Doshi
    17 · 10% · 3265

Your Comment


Sign Up or Login to post a comment.

"relearned how to write a regular expression for validating email addresses" rated 5 out of 5 by 9 readers
relearned how to write a regular expression for validating email addresses , 5.0 out of 5 based on 9 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]