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

3
  • ..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. Commented Jul 22, 2017 at 19:12
  • See Java regex email. Commented Jul 22, 2017 at 19:12
  • @WiktorStribiżew i tried with it also.but i faild. can u show me correct code.i am new for this Commented Jul 22, 2017 at 19:14

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

10 Comments

i got valid to [email protected] also.can u help me
@Intern I missed initial ^ and last $. Check regex again now. Also check the demo.
no friend.i got [email protected] is valid.but should be invalid
question (too lazy to check): does regex101 support Java's idiom of regular expressions?
@CarlosHeuberger I haven't encountered any situation until now where it won't work with java. However, you're right, this flavour isn't mentioned officially on their website.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.