i am using this regex
const emailRegex = new RegExp(/^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[A-Za-z]+$/);
but after i put .au, it considers it an incorrect email
i am using this regex
const emailRegex = new RegExp(/^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[A-Za-z]+$/);
but after i put .au, it considers it an incorrect email
maybe you can specify the number of characters ?
const emailRegex = new RegExp(/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})+$/);
like so
const emailRegex = new RegExp(/^([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9_\-.]+)\.([a-zA-Z]{2,5})+$/);
let matches = 'john.doe@domail.au'.match(emailRegex);
console.log(email);
const rgx = /\b\w+@\w[.\w]+\.\w+\b/g;
Segment | Description |
---|---|
\b\w+@ |
A non-word char to the left and to the right is one or more words, then a literal @ |
\w[.\w]+ |
A word, then either a dot . or a word multiple times in any order. |
.\w+\b |
Next is a dot . followed by one or more words and ending with a word on the left and a non-word on the right. |
Word characters included under the \w
meta sequence are:
A
to Z
and lower a
to z
case letters0
to 9
_
const str = `
user@mail.com
user@sub.domain.net
user@abc
user@
@mail.com
`;
const rgx = /\b\w+@\w[.\w]+\.\w+\b/g;
console.log(str.match(rgx));