poldings
asked on
Validate Email is from Specific Domain
We have a php form that collects some basic information ...
- email
- firstname
- lastname
- company
This signup form is specific to one client so we want to block everyone else from signing up.
Examples of correct email addresses ...
dave@change-domain.co.uk
sue@change-domain.co.uk
sales@change-domain.co.uk
anything@change-domain.co. uk
Any address that does not use '@change-domain.co.uk' is incorrect and should throw up an error ...
"sorry - that email is not valid"
We want the check to be made before form submission - so, after the user enters their email address and tabs to the next field.
Thanks.
- firstname
- lastname
- company
This signup form is specific to one client so we want to block everyone else from signing up.
Examples of correct email addresses ...
dave@change-domain.co.uk
sue@change-domain.co.uk
sales@change-domain.co.uk
anything@change-domain.co.
Any address that does not use '@change-domain.co.uk' is incorrect and should throw up an error ...
"sorry - that email is not valid"
We want the check to be made before form submission - so, after the user enters their email address and tabs to the next field.
Thanks.
<input type='text' name='email' id='email' onchange='validateEmail(th is)'>
function validateEmail(Sender){
var validSuffix = "change-domain.co.uk";
var emailSuffix = Sender.value.substring(Sen der.value. indexOf("@ ")+1);
if(validSuffix != emailSuffix){
alert("sorry - that email is not valid");
Sender.value = "";
Sender.focus();
}
}
function validateEmail(Sender){
var validSuffix = "change-domain.co.uk";
var emailSuffix = Sender.value.substring(Sen
if(validSuffix != emailSuffix){
alert("sorry - that email is not valid");
Sender.value = "";
Sender.focus();
}
}
ASKER
JohnSixkiller:
That works great. Just one thing to make it a bit more user friendly pls ...
How can I adapt it so the focus is back on the 'email' field after the alert has closed?
That works great. Just one thing to make it a bit more user friendly pls ...
How can I adapt it so the focus is back on the 'email' field after the alert has closed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect. Works a treat.
var str= document.form1.emailfield.
var a2 = str.toLowerCase();
if(a2.indexOf("@change-dom
{
alert("sorry - that email is not valid");
}