Skip to content

Instantly share code, notes, and snippets.

@JockPerkins
Created August 30, 2016 14:41
Show Gist options
  • Save JockPerkins/b1a32f3371e2615b5bf5b8dcc5f5b703 to your computer and use it in GitHub Desktop.
Save JockPerkins/b1a32f3371e2615b5bf5b8dcc5f5b703 to your computer and use it in GitHub Desktop.
dfdf
<script>
// Add Date Stamp to form field
$( document ).ready(function() {
var currentDt = new Date();
var mm = currentDt.getMonth() + 1;
var dd = currentDt.getDate();
var yyyy = currentDt.getFullYear();
var date = mm + '/' + dd + '/' + yyyy;
console.log(date);
$("#DateStamp").val(date);
});
// Add validation rules for letters only (first name)
jQuery.validator.addMethod("accept", function(value, element, param) {
return value.match(new RegExp("." + param + "$"));
});
// validate signup form on keyup and submit
$("#mainForm").validate({
rules: {
firstname: {
required: true,
accept: "[a-zA-Z]+"
},
email: {
required: true,
email: true
},
sms_temp: {
phoneUK: true,
minlength: 11,
maxlength: 11
}
},
messages: {
firstname: "Please enter your firstname",
email: "Please enter a valid email address",
sms_temp: "Enter Valid UK Number"
}
});
// Format Numer field to +44
$("#sms_temp").blur(function(){
var numero = $(this).val();
if (numero.charAt(0) == "+" ) { numero = numero.substr(3) }
else { numero = numero.substr(1) }
cleanednumber = "44" + numero;
if (cleanednumber != "") { $("#SMS_formatted").val(cleanednumber); }
});
// After the input changes
$(".formField").on("change", function(){
// Find out which field it is
var the_field = $(this).attr('data-field');
setTimeout(function() {
// If that input has class 'valid'
if($("#"+the_field+" .formField").hasClass("valid")) {
// Update the correlating circle to be filled
$('.circle_'+the_field).addClass('circle_complete');
}
else if($("#"+the_field+" .formField").hasClass("error")) {
// Remove complete class if field then errors out
$('.circle_'+the_field).removeClass('circle_complete');
}
}, 500);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment