/* -------------------------------------
/////////////////////////////////////////
// Simple Form Validation with JQuery. //
/////////////////////////////////////////
// C.Burnett :: 09.05.06 ////////////////
/////////////////////////////////////////
---------------------------------------*/
//var str = 'marcus@airtightdesign.com';str.isEmail();
/* -------------------------------------
/////////////////////////////////////////
// Simple Form Validation with JQuery. //
/////////////////////////////////////////
// C.Burnett :: 09.05.06 ////////////////
/////////////////////////////////////////
---------------------------------------*/
$.fn.validate = function(e) {
$('.form-field-error',this).remove();
$('.radio-field-error',this).remove();
var er = 0;
var region = 0;
var sal = 0;
var isRadio = 0;
var effect = 'fadeIn'; // Pick default effect
var speed = 'fast'; // Choose default speed
// Simple empty field validation
$('.validate-required',this).each(function (i) {
var d = $(this).css('display');
if(d != 'none'){
var type = $(this).attr('type');
if (type == 'text') {
var v = this.value;
}else if (type == 'checkbox') {
var v = this.checked;
}else if (type == 'radio'){
var v = this.checked;
isRadio = 1;
} else {
var v = this.value;
}
var msg = $(this).attr('title');
if (v === '' || v === false) {
html = ''+msg+'';
$('#'+this.id).after(html);
$('#'+this.id).addClass('error-field');
// ScrollTo Requires Interface extensions
if (!er)
$('#'+this.id).ScrollTo(500);
er++;
}else{
$('#'+this.id).removeClass('error-field');
}
}
});
$('.validate-radio',this).each(function (i) {
var d = $(this).css('display');
if(d != 'none'){
var check = false;
$("#"+this.id+" input").each(function () {
if(this.checked){
check = true;
}
});
if(!check) {
var msg = $(this).attr('title');
html = '
'+msg+'
';
$('#'+this.id).before(html);
if (!er)
$('#'+this.id).ScrollTo(500);
er++;
}else{
// Remove error class
}
}
});
$('.validate-year',this).each(function (i) {
var d = $(this).css('display');
if(d != 'none'){
var type = $(this).attr('type');
if (type == 'text') {
var v = this.value;
}else if (type == 'checkbox') {
var v = this.checked;
}else if (type == 'radio'){
var v = this.checked;
isRadio = 1;
}
var msg = $(this).attr('title');
if (v == '' || v == false || isNaN(v) == true || v.length != 4) {
html = ''+msg+'
';
$('#'+this.id).after(html);
$('#'+this.id).addClass('error-field');
// ScrollTo Requires Interface extensions
if (!er)
$('#'+this.id).ScrollTo(500);
er++;
}else{
$('#'+this.id).removeClass('error-field');
}
}
});
$('.validate-zip',this).each(function (i) {
var d = $(this).css('display');
if(d != 'none'){
var type = $(this).attr('type');
if (type == 'text') {
var v = this.value;
}else if (type == 'checkbox') {
var v = this.checked;
}else if (type == 'radio'){
var v = this.checked;
isRadio = 1;
}
var msg = $(this).attr('title');
if (v == '' || v == false || isNaN(v) == true || v.length != 5) {
html = ''+msg+'';
$('#'+this.id).after(html);
$('#'+this.id).addClass('error-field');
// ScrollTo Requires Interface extensions
if (!er)
$('#'+this.id).ScrollTo(500);
er++;
}else{
$('#'+this.id).removeClass('error-field');
}
}
});
$('.validate-ssn',this).each(function (i) {
var d = $(this).css('display');
if(d != 'none'){
var type = $(this).attr('type');
if (type == 'text') {
var v = this.value;
}else if (type == 'checkbox') {
var v = this.checked;
}else if (type == 'radio'){
var v = this.checked;
isRadio = 1;
}
var msg = $(this).attr('title');
if (v == '' || v == false || isNaN(v) == true || v.length != 9) {
html = ''+msg+'';
$('#'+this.id).after(html);
$('#'+this.id).addClass('error-field');
// ScrollTo Requires Interface extensions
if (!er)
$('#'+this.id).ScrollTo(500);
er++;
}else{
$('#'+this.id).removeClass('error-field');
}
}
});
$('.validate-phone',this).each(function (i) {
var d = $(this).css('display');
if(d != 'none'){
var type = $(this).attr('type');
if (type == 'text') {
var v = this.value;
}else if (type == 'checkbox') {
var v = this.checked;
}else if (type == 'radio'){
var v = this.checked;
isRadio = 1;
}
var msg = $(this).attr('title');
if (v == '' || v == false || v.length < 10) {
html = ''+msg+'';
$('#'+this.id).after(html);
$('#'+this.id).addClass('error-field');
// ScrollTo Requires Interface extensions
if (!er)
$('#'+this.id).ScrollTo(500);
er++;
}else{
$('#'+this.id).removeClass('error-field');
}
}
});
// Email validation
$('.validate-email',this).each(function (i) {
var d = $(this).css('display');
if(d != 'none'){
var v = this.value;
var msg = $(this).attr('title');
var reg = new RegExp('^[^@()<>,;:\\\\/"[\\]]+@[^@()<>,;:\\\\/"[\\]]+\\.[a-zA-Z0-9]{2,6}$','');
if(!v.match(reg)){
html = ''+msg+'
';
$('#'+this.id).after(html);
$('#'+this.id).addClass('error-field');
// ScrollTo Requires Interface extensions
if (!er)
$('#'+this.id).ScrollTo(500);
er++;
}else{
$('#'+this.id).removeClass('error-field');
}
}
});
// Catch Submit Event on Error
if (er) {
alert('Please fill in an email address');
//e.preventDefault();
return false;
}else{
return true;
}
}