1

I'm really new to regex in general. All I need is it to check and make sure (Something@something.something) works. I've tried this.

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

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

Corjava
  • 340
  • 2
  • 6
  • 17
  • 1
    Couldn't you test this yourself? Like at http://regexpal.com/ – j08691 Mar 31 '14 at 17:38
  • This may be a good start -> http://stackoverflow.com/questions/940577/javascript-regular-expression-email-validation – lshettyl Mar 31 '14 at 17:39
  • possible duplicate of [jQuery regex validation of e-mail address](http://stackoverflow.com/questions/2855865/jquery-regex-validation-of-e-mail-address) – j08691 Mar 31 '14 at 17:40
  • @j08691 I would have if I knew this website existed. Thanks for showing me. – Corjava Mar 31 '14 at 18:20

2 Answers2

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

tau
  • 6,499
  • 10
  • 37
  • 60
  • 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 Mar 31 '14 at 17:44
0

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

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

mbiokyle
  • 152
  • 9