0

I need check if the address email is correct in markup of my aspx page.

The possible address email correct is :

Name(AndAnyNumber).Surname(AndAnyNumber)@march.com

And I have tried this RegularExpressionValidator :

  <asp:RegularExpressionValidator ID="retxtEmail" runat="server" 
     ControlToValidate="txtEmail"
     ErrorMessage="Not valid" Text="Not valid" Display="Dynamic" 
     ValidationExpression="^([a-z][a-z0-9]*\\.[a-z][a-z0-9]*@march\\.com)$"  
     SetFocusOnError="true" EnableClientScript="true"></asp:RegularExpressionValidator>

Withou success because for address email :

[email protected]

The return is Not valid, why ?

Can you please help me figure out the problem?

Thanks in advance.

2
  • Hm, curious, try "^([a-z][a-z0-9]*[.][a-z][a-z0-9]*@march[.]com)$" Commented Mar 11, 2016 at 9:13
  • I guess it will be due to the double escaped backslash. You do need to escape the ., but try with just the single slash. If that still doesn't work (for example, if asp.net adds the second slash for you) try @WiktorStribiżew suggestion above to escape using [.]. Commented Mar 11, 2016 at 9:26

2 Answers 2

1

There is a problem in your regex.Replace your regex with this:

^([a-zA-Z]+[0-9]+\.[a-zA-Z0-9]+@march\.com)$

if numbers are not mandatory replace [0-9]+ with [0-9]*

Sign up to request clarification or add additional context in comments.

3 Comments

Then his email can start with a number, which he doesn't want
Your ^([a-zA-Z]+[0-9]+.[a-zA-Z0-9][email protected])$ regex now allows the user part and domain part without a dot.
This pattern doesn't match the provided example - not sure why it's been accepted?
1

This regex has been tested as working using Regex Coach (a good free tool for writing regex's).

^[a-z][a-z0-9]*\.[a-z][a-z0-9]*@march\.com$

Issues are:

Using

  • No need for the capturing parentheses
  • Currently case sensitive. Email addresses tend not be be.
  • Double back slashes - this is what was causing issues for me though this might be ASP.NET thing

2 Comments

There must be a problem with your Tool.Regex is not working.
No, the formatting on SO was eating characters. Neededed to change it to be a code snippit for it to include all charatcers. Code now fixed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.