Last active
August 19, 2016 02:14
-
-
Save mistercoffee66/91e3ac3c07ca6bbb6918d568e4572d08 to your computer and use it in GitHub Desktop.
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
var reggie = { | |
email: /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i, | |
password: /^[a-z0-9]{4,25}$/i | |
}, | |
valid = { | |
email: false, | |
password: false | |
}, | |
data = {}; | |
$('#submit').prop('disabled',true); | |
$('.validate').on('blur', function(){ | |
$(this).addClass('dirty'); | |
validate($(this)); | |
}); | |
$('.validate').on('keyup', function(){ | |
validate($(this)); | |
}); | |
$('#submit').on('click', function(e){ | |
e.preventDefault(); | |
submit(data); | |
}); | |
function validate($field) { | |
var id = $field.attr('id'), | |
val = $field.val(); | |
valid[id] = reggie[id].test(val); | |
if (!valid[id]) { | |
if ($field.is('.dirty')) { | |
$field.addClass('error'); | |
} | |
} | |
else { | |
data[id] = val; | |
$field.removeClass('error'); | |
} | |
$('#submit').prop( | |
'disabled', | |
!valid.email || !valid.password | |
); | |
} | |
function submit(data) { | |
//console.log(data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment