2

I am having a problem with SwiftMailer rejecting e-mails containing dots either in the beginning or ending of the address (similarly to multiple dots inside). I would like to make my app noticing about such issues.

What should be the regular expression to filter out wrong e-mail addresses? (by wrong I mean those which are not compiled with the whole standard)

lowtechsun
  • 1,915
  • 5
  • 27
  • 55
  • [Answer from "Using a regular expression to validate an email address"](http://stackoverflow.com/a/201378/626273) – stema Nov 14 '12 at 12:25
  • possible duplicate of [Using a regular expression to validate an email address](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – Frank van Puffelen Nov 18 '12 at 01:48

2 Answers2

1
function check(mail) {
  return !mail.match(/^\.|\.$/);
}
check('amshaegar@example.org'); // true
check('amshaegar@example.org.'); // false
check('.amshaegar@example.org'); // false

The function check expects a mail address as a String and checks if there is no dot(.) at the beginning or end.

For detecting multiple dots(...) as well your function would look like this:

function check(mail) {
  return !mail.match(/^\.|\.{2,}|\.$/);
}
AmShaegar
  • 1,491
  • 9
  • 18
0

The following will find a dot at the beginning of a string or at the end of a string...

^\.|\.$
Vicki
  • 668
  • 7
  • 21