Why Won't This Accept Email Addresses With A Hyphen After The @?
This is the code to sign up to receive email news updates on our site. It works great, unless the email address has a hyphen after the @, then it throws an error box: > The page
Solution 1:
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.
Solution 2:
Try this.
$queryr = sprintf("SELECT emailid FROM master_email WHERE email LIKE '%s' LIMIT 1",
mysql_real_escape_string($email));
and do the same for the insert query.
Also, you're just asking for a SQL Injection :P
Post a Comment for "Why Won't This Accept Email Addresses With A Hyphen After The @?"