1

Needs to only contain [a-zA-Z0-9.], and followed by an @ then the same match afterward, the match before, and after the @ shouldn't be any longer than 64 characters long, and at least one length.

^([a-zA-Z0-9\-\.]+){1,64}@([a-zA-Z0-9\-\.]){1,64}$ 

This seems to work but it sometimes takes forever, why is this?

9
  • 2
    define sometimes takes forever? Commented Jun 27, 2017 at 3:29
  • Can you provide some valid & invalid inputs. Commented Jun 27, 2017 at 3:39
  • "then the same match afterward" - So "abc@abc" would be valid, but "abc@aaa" would not? (I don't really think that's what you meant, but it's what you said.) Why does the part to the left of the "@" have both a + and {1,64}? That allows any number of characters. Remove the +, and if you just want to test "does it match" you can remove all of the parentheses. Commented Jun 27, 2017 at 3:42
  • ^([a-zA-Z0-9\-\.]{1,64})@(\1)$ Like this? Commented Jun 27, 2017 at 3:46
  • Sometime it is getting hanged. It is taking long time. If we try same thing again then it works. Commented Jun 27, 2017 at 3:59

2 Answers 2

1

I'm not sure why you have the + operator in the first part of the regex. I hope this could be useful for you

^([a-zA-Z\d\.]{1,64})@([a-zA-Z\d\.]{1,64})$

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

Comments

0

For email regex you should use http://emailregex.com/ which provides this regex

/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 

also, if you can you should usually just use

<input type="email"> 

1 Comment

You've just copied this from another solution, this does not meet my requirements.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.