github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/js/parsley/parsley.extend.js (about) 1 window.ParsleyConfig = window.ParsleyConfig || {}; 2 3 (function ($) { 4 window.ParsleyConfig = $.extend( true, {}, window.ParsleyConfig, { 5 validators: { 6 minwords: function ( val, nbWords ) { 7 val = val.replace( /(^\s*)|(\s*$)/gi, "" ); 8 val = val.replace( /[ ]{2,}/gi, " " ); 9 val = val.replace( /\n /, "\n" ); 10 val = val.split(' ').length; 11 12 return val >= nbWords; 13 } 14 15 , maxwords : function ( val, nbWords ) { 16 val = val.replace( /(^\s*)|(\s*$)/gi, "" ); 17 val = val.replace( /[ ]{2,}/gi, " " ); 18 val = val.replace( /\n /, "\n" ); 19 val = val.split(' ').length; 20 21 return val <= nbWords; 22 } 23 24 , rangewords: function ( val, obj ) { 25 val = val.replace( /(^\s*)|(\s*$)/gi, "" ); 26 val = val.replace( /[ ]{2,}/gi, " " ); 27 val = val.replace( /\n /, "\n" ); 28 val = val.split(' ').length; 29 30 return val >= obj[0] && val <= obj[1]; 31 } 32 33 , greaterthan: function ( val, elem, self ) { 34 self.options.validateIfUnchanged = true; 35 36 return new Number(val) > new Number($( elem ).val()); 37 } 38 39 , lessthan: function ( val, elem, self ) { 40 self.options.validateIfUnchanged = true; 41 42 return new Number(val) < new Number($( elem ).val()); 43 } 44 45 , beforedate: function ( val, elem, self) { 46 return Date.parse(val) < Date.parse($(elem).val()); 47 } 48 49 , afterdate: function ( val, elem, self) { 50 return Date.parse($(elem).val()) < Date.parse(val); 51 } 52 53 , inlist: function ( val, list, self ) { 54 var delimiter = self.options.inlistDelimiter || ','; 55 var listItems = (list + "").split(new RegExp("\\s*\\" + delimiter + "\\s*")); 56 57 return (listItems.indexOf(val.trim()) !== -1); 58 } 59 60 , luhn: function ( val, elem, self) { 61 val = val.replace(/[ -]/g, ''); 62 var digit, n, sum, _j, _len1, _ref2; 63 sum = 0; 64 _ref2 = val.split('').reverse(); 65 for (n = _j = 0, _len1 = _ref2.length; _j < _len1; n = ++_j) { 66 digit = _ref2[n]; 67 digit = +digit; 68 if (n % 2) { 69 digit *= 2; 70 if (digit < 10) { 71 sum += digit; 72 } else { 73 sum += digit - 9; 74 } 75 } else { 76 sum += digit; 77 } 78 } 79 return sum % 10 === 0; 80 } 81 82 , americandate: function ( val, elem, self) { 83 if(!/^([01]?[0-9])[\.\/-]([0-3]?[0-9])[\.\/-]([0-9]{4}|[0-9]{2})$/.test(val)) { 84 return false; 85 } 86 var parts = val.split(/[.\/-]+/); 87 var day = parseInt(parts[1], 10); 88 var month = parseInt(parts[0], 10); 89 var year = parseInt(parts[2], 10); 90 if(year == 0 || month == 0 || month > 12) { 91 return false; 92 } 93 var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; 94 if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) { 95 monthLength[1] = 29; 96 } 97 return day > 0 && day <= monthLength[month - 1]; 98 } 99 } 100 , messages: { 101 minwords: "This value should have %s words at least." 102 , maxwords: "This value should have %s words maximum." 103 , rangewords: "This value should have between %s and %s words." 104 , greaterthan: "This value should be greater than %s." 105 , lessthan: "This value should be less than %s." 106 , beforedate: "This date should be before %s." 107 , afterdate: "This date should be after %s." 108 , luhn: "This value should pass the luhn test." 109 , americandate: "This value should be a valid date (MM/DD/YYYY)." 110 } 111 }); 112 }(window.jQuery || window.Zepto));