Use the following RegEx:
/(?<=(\s|^))[0-9]{10}\@+[a-zA-Z0-9_.-]+/
See the live demo (Regex101).
If you do not require whitespace before the digit sequence (ie. if these digits needn't make up the whole local name [part before the @
]) drop the lookbehind part ((?<=\s*)
)
Explanation
- Checking for 10 digits before the
@
.
- Checking for a whitespace character or the start of the string before the number portion using negative lookbehind.
- Checking for a syntactically well-formed domain name after the at sign
Notes
'Syntactically well-formed' should be understood as absolutely low-level: Domain names are subject to various constraints that are not validated (eg. ending with a top-level domain). Regexen would be the wrong tool for this.
The check for the domain portion does not cater for internationalised domain names. Have a look at this SO answer to get an idea.
Code Embedding
Turn the regex into a test code as follows:
[
'123456789@example.com '
, '12345678901@example.com '
, 'a1234567890@example.com '
, 'whatever@example.com '
, '1234567890@example.com '
, '1234567890@gargamel.smurf.com '
, ' 1234567890@a.strange.domain.name.but.hey.if.it.gets.resolved....org'
].map ( function ( sample ) {
return /(?<=(\s|^))[0-9]{10}\@+[a-zA-Z0-9_.-]+/.test(sample);
});