Reputation: 19
I am trying to validate a certain subset of the e-mail format with regular expressions, but what I've tried so far doesn't quite work. This is my regex (Java):
boolean x = l.matches(
"^[_A-Za-z0-9-\\\\+]+(\\\\.[_A-Za-z0-9-]+)*@\"\n" +"+ \"[A-Za-z0-9-]+(\\\\.[A-Za-z0-9]+)*(\\\\.[A-Za-z]{2,})$"
);
Thse are the conditions that the string has to match:
- www.fightclub.uk
- www.fightclub.lk
- www.fightclub.sa
- www.fightclub.cc
- www.fightclub.jp
- www.fightclub.se
- www.fightclub.xy
- www.fightclub.gi
- www.fightclub.rl
- www.fightclub.ss
examples:
[email protected]
is valid
[email protected]
is invalid
Upvotes: 0
Views: 1322
Reputation: 31901
You can use:
^[a-z0-9]{3,6}@fightclub\.(?:uk|lk|sa|cc|jp|se|xy|gi|rl|ss)$
^
indicates start of string[a-z0-9]{3,6}
lowercase letters or number with length 3-6 characters@fightclub
\.
(?:
indicate that it's a non-capturing group. All your domain extensions are listed here.$
indicates end of stringDEMO: https://regex101.com/r/rYYXYA/1
Upvotes: 2