0

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:

  • Mail domain is from the list:
    • 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
  • username has 3 to 6 characters(only lowercase English letters and numbers)

examples:

[email protected] is valid

[email protected] is invalid

Sebastian Lenartowicz
  • 4,695
  • 4
  • 28
  • 39
Intern
  • 19
  • 9
  • *..username has 3 to 6 characters(only lowercase English letters and numbers)..* -> `[a-z0-9]{6}` will do it for you. Rest you didn't provide the information for other half. – Am_I_Helpful Jul 22 '17 at 19:12
  • See [*Java regex email*](https://stackoverflow.com/questions/8204680/java-regex-email). – Wiktor Stribiżew Jul 22 '17 at 19:12
  • @WiktorStribiżew i tried with it also.but i faild. can u show me correct code.i am new for this – Intern Jul 22 '17 at 19:14

1 Answers1

2

You can use:

^[a-z0-9]{3,6}@fightclub\.(?:uk|lk|sa|cc|jp|se|xy|gi|rl|ss)$
  1. ^ indicates start of string
  2. [a-z0-9]{3,6} lowercase letters or number with length 3-6 characters
  3. followed by @fightclub
  4. followed by a period \.
  5. followed by a list of domains (?: indicate that it's a non-capturing group. All your domain extensions are listed here.
  6. $ indicates end of string

DEMO: https://regex101.com/r/rYYXYA/1

Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71