At work, our current ValidationExpression looks horrible and very confusing for me. We are using the WebForms <asp:RegularExpressionValidator>
user control which looks like this:
<asp:RegularExpressionValidator ID="regEmail" runat="server"
ValidationGroup="EditEmails"
Text="*" ErrorMessage="Invalid email address."
ControlToValidate="txtAdd"
Display="Dynamic"
ValidationExpression="^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$"/>
I need to somehow alter this to allow apostrophes ( '
) inside an email because at the moment this expression is failing.
Example of an email that needs to pass this validation: Test.O'neill@example.co.uk
I am unsure what the expression does but I'm sure this could be made shorter (maybe not simpler but that does not matter as long as it works).
Anyone know of a better regular expression I could use which works against valid emails and takes this into consideration? Thank you!
EDIT: My question is different because the proposed duplicate question does not work for VB.Net RegularExpression Validator user control.