Created
September 22, 2014 18:58
-
-
Save livercake/5c3e5c2f11d80719c5a5 to your computer and use it in GitHub Desktop.
dead-simple client-side mail validation for form fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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