Skip to content

Instantly share code, notes, and snippets.

@flexbox
Created October 8, 2015 12:22
Show Gist options
  • Save flexbox/508366125f3142be6b27 to your computer and use it in GitHub Desktop.
Save flexbox/508366125f3142be6b27 to your computer and use it in GitHub Desktop.
le wagon lille
// Your validation code will go in there.
// Write your validation functions, and bind events
// in a jQuery DOM ready callback
var EVENTS = 'focusout keyup change';
var ZIP_CODE_PATTERN = /^\d{5}$/;
var MOBILE_PHONE_PATTERN = /^(0|\+33)[1-9]\d{8}$/;
var EMAIL_PATTERN =/^([^\.@]+)(\.([^@]+))?@([^@]+)\.([^@]+)$/;
function checkZipCode(input) {
var zip_code = $(input).val();
addClass(input, zip_code.match(ZIP_CODE_PATTERN));
}
// function checkSomething(input) {
// var ... = $(input).val();
// addClass(input, target.match(..._PATTERN));
// }
function addClass(input, remove) {
var form_group = $(input).parents('.form-group');
if (remove) {
form_group.removeClass('has-error');
if ($(input).val().length > 0) {
form_group.addClass('has-success');
}
} else {
form_group.addClass('has-error').removeClass('has-success');
}
activateButton();
}
function activateButton() {
// var button = $('button[type=submit]');
// 1. We nee to check if .form-group.has-error equals 0
// 2. remove the attribute disabled
}
function onReady() {
$('#zip_code').on(EVENTS, function(event) {
checkZipCode(event.target);
});
}
$(document).ready(onReady);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment