VVV VVV - 1 year ago 73
C# Question

Regular Expression for given scenario

I already have an email address regular expression FROM RFC 2822 FORMAT


but want to modify it to include the following some new conditions:

  1. at least one full stop

  2. at least one @ character

  3. no consecutive full stops

  4. must not start/end with special characters i.e. should only start/end with [0-9a-zA-Z]

  5. should still follow RFC specification for regular expression rules.

Currently the above one allows the email to start with special characters. Also it is allowing two consecutive full stops (except for domain name which is fine, so test@test..com fails and its correct).


Answer Source

No .. and at least 1 . and 1 @.
Also starts/ends with letters/numbers.

The ^ (start) and $ (end) were just added to match a whole string, not just a substring. But you could replace those by a word boundary \b.

An alternative where the special characters aren't hardcoded:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download