Skip to content

Instantly share code, notes, and snippets.

@livercake
Created September 22, 2014 18:58
Show Gist options
  • Save livercake/5c3e5c2f11d80719c5a5 to your computer and use it in GitHub Desktop.
Save livercake/5c3e5c2f11d80719c5a5 to your computer and use it in GitHub Desktop.
dead-simple client-side mail validation for form fields
function validateEmail($email){
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test($email)){
return false;
} else {
return true;
}
}
$(function(){
$('.fail').hide();
$(".submit").click(function(){
var email = $("#email").val();
if ( !validateEmail(email)){
$('.fail').append("Algo anda mal!");
$('.fail').show();
$("#email").focus();
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment