Reputation: 1108
I'm trying to make a form on asp.net where you can send emails. I want to have a textbox where I can type all email addresses which I want to send a message...
However I want to add a validator there so the user always has the correct syntax and therefor, use that string on c# and send the message properly.
For now, I have a validator for a single email address...
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server"
ControlToValidate="tbxAlClEmail" ErrorMessage="E-mail Invalido"
Font-Bold="True" ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="vgpNuevoCliente">
</asp:RegularExpressionValidator>
so, we can see that.... email = \w+([-+.']\w+)@\w+([-.]\w+).\w+([-.]\w+)*
(I know that it is difficult to find an expression regular that can validate all kind of email addresses... but this will have to do)
now I want to addapt this regular expression to an asp.net validator:
email ( (,|;) [SPACE]* email )*
example of results i want:
[email protected], [email protected],[email protected]; [email protected]
I hope you can help me with that... Thanks in advance
Upvotes: 0
Views: 1620
Reputation: 88044
What you have won't work to validate email addresses.
Using regex for email validation is extremely hard to do right and there are literally hundreds of examples on the net of validators that get close... but still aren't perfect.
But that's only a small part of the problem anyway. Your absolute best bet is to drop trying to validate the address and simply send the messages while telling the user which addresses failed.
If you are doing it right, then you aren't including every address in the TO field anyway and instead are sending distinct messages to each individual address. Which would make it fairly easy to report errors.
Of course, even then numerous mail servers are configured to not even respond if a bad email address is sent to it and instead they just black hole the message. No amount of validation etc is going to get past that.
For fun, you might want to read the following in its entirety so that you understand the full problem: http://www.regular-expressions.info/email.html
Upvotes: 1