I am looking for a basic email validation using HTML5 pattern. So far I have the following but I am struggling with the required rules below, esp. rules 1 and 3.
Conditions:
- I only need to cover email addresses containing **letters (a-zA-Z), digits (0-9), underscores (_), dots / periods (.), dashes (-).
- I only need to cover standard business email addresses such as firstname.lastname@domain.com, firstname.lastname@domain.co.uk, firstname.lastname@domain.de, firstname-secondname.lastname@domainPart1-domainPart2.de.
- No need to cover Asian or Arabic characters and no need to cover characters not listed here.
- No need to cover emails not containing dot / period.
Required rules:
- First character cannot be underscore, dot / period or dash.
- Last character cannot be underscore, dot / period or dash.
- Cannot contain two dots / periods in a row.
- Cannot contain spaces (also not as first or last character).
My approach (not working):
<input type="email" id="email" minlength="10" pattern="^(?!^\.\_\-)(?!.*[-_.]$)[a-zA-Z0-9\.\_\-]+$" required autocomplete="off">
Can someone show me how to do this right and also provide an explanation on the single parts?