0

I found this regex:

^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$

but I have 2 problems with it:

  1. I can't enter a single letter domain - like: a@a.me
  2. I can enter slashback \ which is not valid

Can you help fixing this?

MojoDK
  • 4,410
  • 10
  • 42
  • 80
  • @Necreaux - might be possible, but I'm still interested in knowing why [\w\.-] only allows 1 character (I'm a regex noob). – MojoDK Mar 26 '15 at 13:14

2 Answers2

1
  1. \w[\w\.-]+ reads "a alphanum char followed by one or more alphanumchar, dot or dash". You thus need \w[\w\.-]*: "a alphanum char followed by zero or more alphanumchar, dot or dash".

  2. [^\s()<>@,;:\/] lists all the chars that are not allowed: \s()<>@,;:/ (\/ is actually an escaped /). You thus need to add the (escaped) backslash: [^\s()<>@,;:\/\\].

sp00m
  • 47,968
  • 31
  • 142
  • 252
0
^[^\s()<>@,;:\/\\]+@\w([\w\.-]+)?\.[a-z]{2,}$
Bogdan
  • 89
  • 2