1

Recently, I updated some code to use System.Net.Mail.MailAddress() to check if an e-mail address is valid or not. Shortly after, I noticed some email addresses with commas in the domain name are considered valid, for example, the code below will indicate the email address is Valid???

Good grief! -- how are the rest of you handling this??

dim ok as Boolean

dim test_str as String = "someone@comma,com"

dim email as System.Net.Mail.MailAddress

ok = true

Try 
   email = new System.Net.Mail.MailAddress( test_str )
Catch ex As Exception
   ok = false
End Try   

if ( ok ) then
   response.write( "Valid" )
else
   response.write( "INVALID" )
end if
bdcoder
  • 3,280
  • 8
  • 35
  • 55
  • presumably by validating the email address: a reg ex is a common way. – Mitch Wheat Dec 02 '12 at 04:51
  • http://stackoverflow.com/questions/369543/validating-e-mail-with-regular-expression-vb-net – jchapa Dec 02 '12 at 05:25
  • @MitchWheat - I think regex is [not the correct way](http://stackoverflow.com/a/201378/1379664) to validate an email address. – Blachshma Dec 02 '12 at 08:04
  • @MitchWheat being common doesn't mean it's right :) Are you saying that there is a regex that *100%* validates if an inputted string is a valid email address? – Blachshma Dec 02 '12 at 08:47
  • No, I didn't say that. You are putting words in my mouth. You will notice I said " a common way" and not "a 100% correct way". – Mitch Wheat Dec 02 '12 at 10:35

0 Answers0