Last active
August 29, 2015 14:18
-
-
Save pketh/84ee7ac16091b5c58b51 to your computer and use it in GitHub Desktop.
validates emails with hooks for doing other things
This file contains 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
validateEmail = (email, input) -> | |
emailPattern = /^[A-Za-z0-9](([_\.\-+]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/i | |
if emailPattern.test(email) | |
addSuccessCookie() | |
return true | |
else | |
input.addClass('fail') | |
return false | |
addSuccessCookie = () -> | |
console.log "on success, I add the success cookie" | |
$('.submit-link').click -> | |
form = $(this).prev() | |
form.trigger('submit') | |
$('.newsletter-form').submit -> | |
input = $(this).find('input') | |
email = input.val().trim() | |
validateEmail(email, input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment