.NET: Email Address Parsing - save with RegExp or just Try/Catch around Mail.MailAddressParser? -


what recommend simple result "ismailvalid?" -> true|false?

  • is save use regexp
  • is better use .net's system...mail.mailaddressparser simple try/catch around it?

since speed not relevant, think going way mailaddressparser ok?

regards

john

given requirements speed not being necessary, use mail.mailaddressparser try/catch. it's guaranteed filter out .net runtime can't recognize valid email address, , simpler.

a regex same, bad regex give false positives, false negatives, or both.

the performance cost in handling exceptions make me go other way if speed factor, in case, requirements, less code, more readable code, , "just works" balance out performance factor.

clarification:

i'm assuming intended code this:

try {    system.net.mail.mailaddress address = new system.net.mail.mailaddress(somestring); } catch(exception ex) {    // handle invalid email addresses here. } 

and recommendation situation. intentional exception best practices of not using exceptions other methods work , only suggested because of explicit statement performance not factor.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -