1

I'm really new to regex in general. All I need is it to check and make sure ([email protected]) works. I've tried this.

var checkEmail = /^\w+@\w+.[a-zA-Z]/;

Is something like this correct for what I'm looking for?

4

2 Answers 2

2

To refine what you have:

var checkEmail = /^\w+@\w+\.[a-zA-Z]+/;

What you posted it close (you should escape the . so it doesn't match any character and add a + after the [a-zA-Z] because top-level domains are at least 2 character I think), but for something like an email address that actually has a long and little known spec, I would just use someone else's regex.

Here's a site with more info:

http://www.regular-expressions.info/email.html

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

1 Comment

Yeah, I've seen some very specific realistic regex for E-Mails, but this is just for a class assignment that doesn't need all the specifics. Thanks for the help though.
0

You should escape the dot, otherwise it is a meta character that matches anything. Try:

/^\w+@\w+.[a-zA-Z]/

Comments

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.