[Solved] Why won’t this accept email addresses with a hyphen after the @?


Try this:

var emailpat = /^[^@]+@[^@]+\.[^@\.]{2,}$/;

Email addresses should have just one @-sign, and that can’t be the first character. After the @ you’ll need at least one dot followed by 2 or more letters.

And yes, this also accepts email addresses that are not valid. If you want to be sure that the user enters a valid email address, you should send an email to the address and wait for the user to take action (ie enter a code that’s in the email).

Edit

Updated regex so the domain part is no longer restricted to roman alphabet TLDs. Other alphabets are allowed, although probably not very common (yet). See wikipedia for examples.

5

solved Why won’t this accept email addresses with a hyphen after the @?