So yesterday while mass mailing our students, one or more emails failed and consequently threw an unhandled exception in our application. before sending any mails however, the list of emails pulled from the db are checked for validity using the following regular expression: (vb code, VS2008)
Code: Select all
If Regex.Match(email, "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*").Success Then
Return True
Else
Return False
End If
I'm not really good with regex and to be brutally honest, I didn't build the above expression, nor do I even completely understand it. (We don't use regular expressions all that much) Which is why I'm posting this here. Can anyone find fault with the expression used? Would it allow an address that would fail when sending?
The other thing that bugs me is that we are using vb with its inbuilt system.net.mail, and I'm unsure if this will throw an exception when, for instance, an address is valid, but spelt incorrectly. If this is the case then I well, **** (Also, then we probably would get more than one error, which we don't).
Right now I'm only concerned with allowing valid emails. I'll worry about incorrect spelling later.
Any help?