-2

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

lams
  • 352
  • 1
  • 10

2 Answers2

1

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);
coderpolo
  • 307
  • 3
  • 12
0
const rgx = /\b\w+@\w[.\w]+\.\w+\b/g;

Regex101

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:

  • Upper A to Z and lower a to z case letters
  • Digits 0 to 9
  • Underscore _

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));
zer00ne
  • 41,936
  • 6
  • 41
  • 68