PageSourceSearch

https://www.cando-web.co.jp/js/form-validate.js?20250324_2

js cando-web.co.jp collected 2026-10-03 19:01:06 UTC 12,117 bytes, 416 lines download raw bytes

1(function ($) {
2  'use strict';
3  
4  var BGValidateOffset = 0;
5
6  // for legacy browser
7  if (!Array.prototype.indexOf) {
8    Array.prototype.indexOf = function (searchElement) {
9      for(var i = 0; i < this.length; i += 1) {
10        if (this[i] === searchElement) return i;
11      }
12      return -1;
13    }
14  }
15
16  // type name to use
17  var typeNames = [
18    'numeric',
19    'alphabetic',
20    'alphanumeric',
21    'ascii',
22    'mail',
23    'tel',
24    'hiragana',
25    'katakana',
26    'zenkaku'
27  ];
28
29  // check character
30  var checkChar = {
31    ascii: function (target) {
32      return !target || (/^[\x20-\x7E]+$/).test(target);
33    },
34
35    numeric: function (target) {
36      return !target || (/^[0-9]+$/).test(target);
37    },
38
39    alphabetic: function (target) {
40      return !target || (/^[a-zA-Z]+$/).test(target);
41    },
42
43    alphanumeric: function (target) {
44      return !target || (/^[a-zA-Z0-9]+$/).test(target);
45    },
46
47    hiragana: function (target) {
48      return !target || (/^[ぁ-ん]+$/).test(target);
49    },
50
51    katakana: function (target) {
52      return !target || (/^[ァ-ン]+$/).test(target);
53    },
54
55    mail: function (target) {
56      return !target || (/^([a-zA-Z0-9])+([a-zA-Z0-9\+\._-])*@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/).test(target);
57    },
58    tel: function (target) {
59      return !target || (/^[0-9\-]+$/).test(target);
60    },
61
62    zenkaku: function (target) {
63      var i, charCode;
64
65      for (i = 0; i < target.length; i += 1) {
66        charCode = target.charCodeAt(i);
67        if (charCode < 256 || (charCode >= 0xff61 && charCode <= 0xff9f)) {
68          return false;
69        }
70      }
71
72      return true;
73    },
74
75    convertBreak: function (target) {
76      return target.replace(/\r\n/g, '<br>').replace(/(\n|\r)/g, '<br>');
77    }
78  };
79
80  // check required
81  var checkRequired = function ($el, msg) {
82    if ($el.prop('disabled')) {
83      return true;
84    }
85    var result = false;
86    var node = $el[0].nodeName.toLowerCase();
87    var type = $el.attr('type');
88
89    // select
90    if (node === 'select') {
91      result =  $el.val() &&  $el.val().trim() !== '' ? checkOK($el) : checkNG($el, msg);
92
93    // input or textarea
94    } else if (node === 'input' || node === 'textarea') {
95      if (type === 'checkbox') {
96        result = $el.prop('checked') ? checkOK($el) : checkNG($el, msg);
97
98      } else if (type === 'radio') { // radio ボタンが class しかないから無理やりの処理
99        result = $('input[name="class"]').is(':checked') ? checkOK($el) : checkNG($el, msg);
100
101      } else {
102        result = $.trim($el.val()) !== '' ? checkOK($el) : checkNG($el, msg);
103      }
104    }
105
106    // set result
107    $el.data('required', result);
108
109    return result;
110  };
111
112  // check whichrequired
113  var checkWhichRequired = function ($el, msg) {
114    var result = false;
115    var resultFlag = false;
116    var node = $el[0].nodeName.toLowerCase();
117    var type = $el.attr('type');
118    var which = $el.attr('whichrequired');
119
120    $('[whichrequired="' + which + '"]').each ( function() {
121      resultFlag = $.trim($(this).val()) !== '' ? true : false;
122      if ( resultFlag ) {
123        return false;
124      }
125    });
126    $('[whichrequired="' + which + '"]').each ( function() {
127      result = resultFlag === true ? checkOK($(this), msg) : checkNG($(this), msg);
128    });
129    
130
131    // set result
132    $el.data('whichrequired', result);
133
134    return result;
135  };
136
137  // check whichrequired
138  var checkWhichRequiredForCheckbox = function ($el, msg) {
139    var result = false;
140    var resultFlag = false;
141    var node = $el[0].nodeName.toLowerCase();
142    var type = $el.attr('type');
143    var which = $el.attr('whichrequired');
144
145    $el.find('[type="checkbox"]').each ( function() {
146      resultFlag = $(this).prop('checked') ? true : false;
147      if ( resultFlag ) {
148        return false;
149      }
150    });
151    $el.find('[type="checkbox"]').each ( function() {
152      result = resultFlag === true ? checkOK($(this), msg) : checkNG($(this), msg);
153    });
154    
155
156    // set result
157    $el.data('whichRequiredForCheckbox', result);
158
159    return result;
160  };
161
162  // check input
163  var checkInput = function ($el, type, msg) {
164    var result = false;
165
166    if ($el.data('required') !== false) {
167      result = checkChar[type]($el.val()) ? checkOK($el) : checkNG($el, msg);
168
169      // set data into this object
170      $el.data('input', result);
171    }
172
173    return result;
174  };
175
176  // check minimum length
177  var checkLength = function ($el, msg) {
178    var result = false;
179
180    if ($el.data('required') !== false && $el.data('input') !== false) {
181      var length = $el.val().length;
182      var minlength = $el.attr('minlength');
183
184      msg = minlength + msg;
185      if ( length == 0 ) {
186          result = checkOK($el);
187      }
188      else {
189          result = length >= minlength ? checkOK($el) : checkNG($el, msg);
190      }
191      
192      // set data into this object
193      $el.data('minlength', result);
194    }
195
196    return result;
197  };
198  
199  // check equal
200  var checkEqual = function ($el, msg) {
201    var result = false;
202
203    if ($el.data('required') !== false && $el.data('input') !== false) {
204      var equal = $el.val();
205      var equalTarget = '#' + $el.attr('data-equal');
206      var equalTargetStr = $(equalTarget).val();
207
208      result = equal == equalTargetStr ? checkOK($el) : checkNG($el, msg);
209
210      // set data into this object
211      $el.data('equal', result);
212    }
213
214    return result;
215  };
216  
217  // check nospace
218  var checkNospace = function ($el, msg) {
219    var result = false;
220
221    result = $.trim($el.val()) !== '' ? checkOK($el) : ($el.val() === '' ? checkOK($el) : checkNG($el, msg));
222
223    // set result
224    $el.data('nospace', result);
225
226    return result;
227  };
228
229  var checkOK = function ($el) {
230    $el.parents('li').removeClass('error');
231    $el.parents('.validate-box').find('.error-txt').text('').hide();
232    return true;
233  };
234
235  var checkNG = function ($el, text) {
236    $el.parents('li').addClass('error');
237    $el.parents('.validate-box').find('.error-txt').text(text).show();
238    var moveOffset = $el.parents('.validate-box').offset().top - $('#header').height() - 100;
239    if ( BGValidateOffset == 0 || BGValidateOffset > moveOffset ) {
240      BGValidateOffset = moveOffset;
241      // エラーが発生した入力欄にフォーカスを設定
242      $el.focus();
243    }
244    return false;
245  };
246
247  // jQuery extend
248  $.fn.formValidate = function (messages, options) {
249    BGValidateOffset = 0;
250  
251    // messages and default
252    messages = $.extend({
253      whichRequiredForCheckbox: 'チェックを入力してください',
254      whichrequired: 'どちらかを入力してください',
255      required: '入力してください',
256      numeric: '数字で入力してください',
257      alphabetic: 'アルファベットで入力してください',
258      alphanumeric: 'アルファベットか数字で入力してください',
259      ascii: '半角英数字で入力してください',
260      mail: 'メールアドレスを入力してください',
261      tel: '電話番号を入力してください',
262      hiragana: 'ひらがなで入力してください',
263      katakana: 'カタカナで入力してください',
264      zenkaku: '全角で入力してください',
265      minlength: '文字以上を入力してください',
266      equal: '入力内容が一致しません',
267      nospace: '空白文字だけの入力は出来ません'
268    }, messages);
269
270    // options and default
271    options = $.extend({
272      changeEvent: true,
273      submitEvent: true
274    }, options);
275
276    return this.each(function () {
277      // change event
278      if (options.changeEvent) {
279        var selectors = '.whichrequired, .required, .minlength, .' + typeNames.join(', .');
280
281        $(this).find(selectors).change(function () {
282          var $this = $(this);
283          var i;
284
285          // check whichrequired
286          if ($this.hasClass('whichrequired')) {
287            checkWhichRequired($this, messages.whichrequired);
288          }
289
290          // check required
291          if ($this.hasClass('required')) {
292            checkRequired($this, messages.required);
293          }
294
295          // check input
296          for (i = 0; i < typeNames.length; i += 1) {
297            var typeName = typeNames[i];
298            var message = messages[typeName];
299
300            if ($this.hasClass(typeName)) {
301              checkInput($this, typeName, message);
302            }
303          }
304
305          // check minimum length
306          if ($this.hasClass('minlength')) {
307            checkLength($(this), messages.minlength);
308          }
309          
310          // check equal
311          if ($this.hasClass('equal')) {
312            checkEqual($this, messages.equal);
313          }
314          
315          // check nospace
316          if ( $this.hasClass('nospace')) {
317            checkNospace($this, messages.nospace);
318          }
319        });
320      }
321
322      // submit event
323      //$(this).submit(function () {
324        $('.confirm-btn').off('click').on('click', function () {
325        var $this = $(this).closest('form');
326        var i, j = 0;
327        var results = [];
328        
329        // check whichrequired
330        $this.find('input.whichrequired,select.whichrequired,textarea.whichrequired').each(function () {
331          results[j] = checkWhichRequired($(this), messages.whichrequired);
332          j += 1;
333        });
334
335        // check whichrequired for checkbox
336        $this.find('.wpcf7-checkbox.required').each(function () {
337          results[j] = checkWhichRequiredForCheckbox($(this), messages.whichRequiredForCheckbox);
338          j += 1;
339        });
340
341        // check required
342        $this.find('select.required').each(function () {
343          results[j] = checkRequired($(this), messages.required);
344          j += 1;
345        });
346
347        // check required
348        $this.find('input.required').each(function () {
349          results[j] = checkRequired($(this), messages.required);
350          j += 1;
351        });
352        // check required
353        $this.find('textarea.required').each(function () {
354          results[j] = checkRequired($(this), messages.required);
355          j += 1;
356        });
357
358        // check input
359        for (i = 0; i < typeNames.length; i += 1) {
360          var typeName = typeNames[i];
361          var message = messages[typeName];
362
363          $this.find('.' + typeName).each(function () {
364            results[j] = checkInput($(this), typeName, message);
365            j += 1;
366          });
367        }
368
369        // check minimum length
370        $this.find('.minlength').each(function (i) {
371          results[j] = checkLength($(this), messages.minlength);
372          j += 1;
373        });
374
375        // check equal
376        $this.find('.equal').each(function (i) {
377          results[j] = checkEqual($(this), messages.equal);
378          j += 1;
379        });
380        
381        // check nospace
382        $this.find('.nospace').each(function (i) {
383          results[j] = checkNospace($(this), messages.nospace);
384          j += 1;
385        });
386          
387        // handler at before submit
388        if ( results.indexOf(false) === -1 ) {
389          if ( options.beforeSubmit ) {
390            if ( !options.beforeSubmit() ) {
391              return false;
392            }
393          }
394        }
395
396        if ( BGValidateOffset != 0 ) {
397          $('body,html').animate({ scrollTop: BGValidateOffset }, 500);
398        }
399        BGValidateOffset = 0; // reset
400        
401        // handler at notFalseSubmit
402        if ( results.indexOf(false) === -1 ) {
403          if ( options.notFalseSubmit ) {
404            if ( !options.notFalseSubmit() ) {
405              return false;
406            }
407          }
408        }
409        
410        return options.submitEvent && (results.indexOf(false) === -1);
411      });
412    });
413
414  }
415  
416})(jQuery);

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.