Validate/accept only emails from a specific domain name
HTML
<form id="signup" method="post">
<input type="email" placeholder="Your e-mail." />
<button>Submit</button>
</form>
CSS
button, input {
display: block;
margin: 10px;
}
footer{
background: #ff0;
border: 0 none;
border-top: 1px solid #000;
bottom: 0;
padding: 10px;
position: fixed;
width: 100%;
}
JavaScript
$('#signup').submit(function() {
validateEmail($('input').val());
return false;
});
function validateEmail(email) {
//if(re.test(email)){
//Email valid. Procees to test if it's from the right domain (Second argument is to check that the string ENDS with this domain, and that it doesn't just contain it)
if(email.indexOf(".ac.uk", email.length - ".ac.uk".length) !== -1){
//VALID
alert("VALID");
}
else alert("not valid");
//}
}