There is something not quite right with this. Can anyone help?
I want to say that if the email textbox is not empty, then do the Email validation, which does work on its own. It is part of a function.
There is something wrong with the first if....???
if (!(document.frmRegister.email.value.length = 0))
{
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.frmRegister.email.value)))
{
messagebox += "You must enter a valid Email address, please try again \n";
}
}
}
if (document.frmRegister.email.value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/) != null) {
messagebox += "You must enter a valid Email address, please try again \n";
}
You dont need to test for length, if they don't enter anything it will fail the regexp anyway.
It was nearly correct, thanks very much - I think this way is now working,
if (!(!(document.frmRegister.email.value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)== null)))
{
messagebox += "You must enter a valid Email address, please try again \n";
}
Do not use the JavaScript shown on this web page to validate email addresses. All of the examples shown here are wrong..
For more information, see http://www.iana.org/domains/root/db/ for a list of valid top level domains. See especially the "gTLDs" section (there is a link to that section at the top of the page). The JavaScript examples on this page assume a top level domain name can only have 2 or 3 characters. That has not been correct for over 10 years, and if you use this JavaScript many people will be unable to enter their valid email addresses into your web page.
Do not attempt to validate email addresses using JavaScript unless:
You are capable of writing the JavaScript yourself without seeking assistance from a web forum;
You test your code extensively; and
You are ready and able to monitor the IANA list and keep your code up to date;
Bookmarks