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

1
  • 1
    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.
    – Corjava
    Commented Mar 31, 2014 at 17:44
0

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.