1$(function() { 2 3 // add * for required fields 4 var label; 5 $('form div.required').each(function() { 6 label = $(this).find('label').html(); 7 $(this).find('label').html(label + " *"); 8 }); 9 10 $(".numeric").keydown(function (e) { 11 // Allow: backspace, delete, tab, escape, enter and . 12 if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190, 110]) !== -1 || 13 // Allow: Ctrl+A 14 (e.keyCode == 65 && e.ctrlKey === true) || 15 // Allow: home, end, left, right 16 (e.keyCode >= 35 && e.keyCode <= 39)) { 17 // let it happen, don't do anything 18 return; 19 } 20 // Ensure that it is a number and stop the keypress 21 if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) { 22 e.preventDefault(); 23 } 24 }); 25 26 // masking 27 $("input.phone").mask("(999) 999-9999"); 28 $("input.cc_expiration").mask("99/99"); 29 $("input.date").mask("99/99/9999"); 30 31 $('form').submit(function() { 32 // clear messages 33 $(this).find('.error').removeClass('error'); 34 var error = 0; 35 var top_error = 100000; 36 37 // check for missing required fields 38 $(this).find('div.required:visible').each(function() { 39 if ($(this).hasClass("radio-required")) { 40 var name = $(this).find('input[type=radio]').attr('name'); 41 if ($('input[name=' + name + ']:checked').length == 0) { 42 $(this).addClass('error'); 43 $(this).addClass('error'); 44 if ($(this).position().top < top_error) top_error = $(this).position().top; 45 error = 1; 46 } 47 48 } else if ($(this).hasClass("email")) { 49 // email validation 50 var email_regex = /\b[\w\+\.-]+@[\w\.-]+\.\w{2,4}\b/; 51 if (!email_regex.test($(this).find('.data').val())) { 52 $(this).addClass('error'); 53 $(this).addClass('error'); 54 if ($(this).position().top < top_error) top_error = $(this).position().top; 55 error = 1; 56 } 57 58 } else if ($(this).hasClass("cc_expiration")) { 59 60 var entered_expiration = $(this).find('.data').val().split("/"); 61 entered_expiration = '20' + entered_expiration[1] + '' + entered_expiration[0]; 62 63 var declinable_expiration = $(this).data("decline").split("/"); 64 declinable_expiration = declinable_expiration[1] + '' + declinable_expiration[0]; 65 66 if (is_empty($(this).find('.data').val())) { /* empty string decline */ 67 68 $(this).addClass('error'); 69 if ($(this).position().top < top_error) top_error = $(this).position().top; 70 error = 1; 71 72 } else if (declinable_expiration > 0) { /* expired based on custom target range */ 73 74 if (entered_expiration <= declinable_expiration) { 75 $(this).addClass('error'); 76 if ($(this).position().top < top_error) top_error = $(this).position().top; 77 error = 1; 78 79 } 80 81 } else { /* decline based on current month and year */ 82 83 var d = new Date(), n = d.getMonth() + 1, y = d.getFullYear(); 84 if (n < 10) n = "0" + n; 85 declinable_expiration = y + "" + n; 86 87 if (entered_expiration < declinable_expiration) { 88 $(this).addClass('error'); 89 if ($(this).position().top < top_error) top_error = $(this).position().top; 90 error = 1; 91 } 92 93 } 94 95 } else { 96 if (is_empty($(this).find('.data').val())) { 97 $(this).addClass('error'); 98 $(this).addClass('error'); 99 if ($(this).position().top < top_error) top_error = $(this).position().top; 100 error = 1; 101 } 102 } 103 }); 104 105 // check for passwords matching if password2 field exists 106 if (!error && $('#password2').length) { 107 if ($('#password').val() != $('#password2').val()) { 108 $('#password, #password2').val(''); 109 $('#password').parent('div').addClass('error'); 110 if ($('#password').position().top < top_error) top_error = $('#password').position().top; 111 error = 1; 112 } 113 } 114 if (error) { 115 $.scrollTo(top_error, 200); 116 return false; 117 } 118 }); 119}); 120 121function is_empty(val) { 122 if (!val) return true; 123 else if (is_array(val)) { 124 if (val[0] == 0) return true; 125 else return false; 126 } 127 else if ((val.length==0) || (val == null) || (val == 0)) { 128 return true; 129 } 130 else { 131 return false; 132 } 133} 134function is_array(obj) { 135 if (!obj || obj.constructor.toString().indexOf("Array") == -1) return false;
136 else return true; 137}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.