PageSourceSearch

https://www.astyle.jp/astyle/contents/js/validator.js?var=20260926_test

js astyle.jp collected 2026-09-25 18:44:13 UTC 19,394 bytes, 562 lines download raw bytes

1var Validator = {
2    errorId: '__error_',
3    existsErrorId: 'isExistsError',
4    errorGroupNotExistClassName: 'errorMessage',
5    errorGroupClassName: 'errorMessage alertMsg alertMsg-error',
6    check : function(field, reg, extra) {
7        var response;
8        var rule = this.rule;
9        rule.field = field;
10        rule.value = field.value;
11        rule.extra = extra;
12
13        if (reg == "input") {
14            response = rule.input();
15        } else if (reg && !response && rule.value != '') {
16            reg = reg.replace(/^!/, '');
17
18            var mode = reg.split(/\s+/);
19            for ( var i = 0, m; m = mode[i]; i++) {
20                m = m.replace(/([\d?\.\-:]+)?$/, '');
21                response = rule[m](RegExp.$1);
22                if (response) {
23                    break;
24                }
25            }
26        }
27
28        if (response) {
29            this.output(field, response);
30            return false;
31        } else {
32            return true;
33        }
34    },
35
36    checkTel : function(telId, telNo) {
37        var response;
38        var rule = this.rule;
39        rule.value = telNo;
40
41        response = rule.tel();
42        if (response) {
43            this.outputbyId(telId, response);
44            return false;
45        } else {
46            return true;
47        }
48    },
49
50    checkZip : function(zipId, zipNo) {
51        var response;
52        var rule = this.rule;
53        rule.value = zipNo;
54
55        response = rule.zip();
56        if (response) {
57            this.outputbyId(zipId, response);
58            return false;
59        } else {
60            return true;
61        }
62    },
63
64    allclose : function(form) {
65        for (var i = 0, f; f = form[i]; i++) {
66            this.init(f);
67        }
68    },
69
70    init : function(field) {
71        if (field == null || field == undefined) {
72            return;
73        }
74
75        var id = field.id;
76        if (field.type == 'radio' || field.type == 'checkbox') {
77            id = id.replace(/_0$/, '');
78        }
79
80        var className = field.className;
81        if (!isNullorUndefinedorEmpty(className)) {
82            if (className.indexOf("TEL_1") >= 0 || className.indexOf("ZIP_1") >= 0) {
83                id = id.replace('Pre', '');
84            } else if (className.indexOf("TEL_2") >= 0) {
85                id = id.replace('Middle', '');
86            } else if (className.indexOf("TEL_3") >= 0 || className.indexOf("ZIP_2") >= 0) {
87                id = id.replace('Post', '');
88            }
89        }
90
91        this.initbyId(id);
92    },
93
94    initbyId : function(id, msg) {
95        var errorId = this.errorId + id;
96        var errorElement = document.getElementById(errorId);
97        if (errorElement != null && errorElement != undefined) {
98            if (errorElement.innerHTML != undefined) {
99                errorElement.innerHTML = "";
100
101                if(!this.isExistErrorMessageWithScreenError()){
102                    var existsErrorElement = document.getElementById(this.existsErrorId);
103                    if (existsErrorElement != null && existsErrorElement != undefined) {
104                        existsErrorElement.innerHTML = "";
105                        existsErrorElement.className = this.errorGroupNotExistClassName;
106                    }
107                }
108            }
109        }
110    },
111
112    output : function(field, msg) {
113        if (field == null || field == undefined || msg == null || msg == undefined || msg == "") {
114            return;
115        }
116
117        var id = field.id;
118        if (field.type == 'radio' || field.type == 'checkbox') {
119            id = id.replace(/_0$/, '');
120        }
121        var className = field.className;
122        if (!isNullorUndefinedorEmpty(className)) {
123            if (className.indexOf("TEL_1") >= 0 || className.indexOf("ZIP_1") >= 0) {
124                id = id.replace('Pre', '');
125            } else if (className.indexOf("TEL_2") >= 0) {
126                id = id.replace('Middle', '');
127            } else if (className.indexOf("TEL_3") >= 0 || className.indexOf("ZIP_2") >= 0) {
128                id = id.replace('Post', '');
129            }
130        }
131        this.outputbyId(id, msg);
132    },
133
134    outputbyId : function(id, msg) {
135        var errorId = this.errorId + id;
136        var errorElement = document.getElementById(errorId);
137        if (errorElement != null && errorElement != undefined) {
138            var systemMessageContents = document.getElementsByClassName('systemMessageContent');
139            for (var i = 0; i < systemMessageContents.length; i++) {
140                var systemMessageContent = systemMessageContents[i];
141                systemMessageContent.remove();
142            }
143
144            if (this.isExistSameErrorThisChildElements(errorElement, msg)) {
145                return;
146            }
147
148            var outputError = document.createElement('span');
149            outputError.className = 'alertMessage alertMessageContent alertMessage-important';
150            outputError.innerHTML = msg;
151            errorElement.appendChild(outputError);
152
153            var existsErrorElement = document.getElementById(this.existsErrorId);
154            if (existsErrorElement != null && existsErrorElement != undefined) {
155                existsErrorElement.className = this.errorGroupClassName;
156
157                var errorExistMessage = this.rule.submit();
158                if (existsErrorElement.innerHTML.indexOf(errorExistMessage) < 0) {
159                    var outputExistsError = document.createElement('span');
160                    outputExistsError.className = 'alertMessageContentTitle';
161                    outputExistsError.innerHTML = errorExistMessage;
162                    existsErrorElement.innerHTML = outputExistsError.outerHTML;
163                }
164            }
165        }
166    },
167
168    isExistSameErrorThisChildElements : function(errorElement, msg) {
169        if (isNullorUndefined(errorElement)) {
170            return false;
171        }
172
173        if (isNullorUndefined(errorElement.childNodes) || errorElement.childNodes.length == 0) {
174            return false;
175        }
176
177        var childNodes = errorElement.childNodes;
178        for (var i = 0; i < childNodes.length; i++) {
179            var child = childNodes[i];
180            if (isNullorUndefined(child) || isNullorUndefinedorEmpty(child.innerHTML)) {
181                continue;
182            }
183            if (child.innerHTML.indexOf(msg) >= 0) {
184                return true;
185            }
186        }
187        return false;
188    },
189
190    getAlertMessageContents : function() {
191        return $('.alertMessage');
192    },
193
194    isExistErrorMessage : function() {
195        var alertMessageContents = this.getAlertMessageContents();
196        if (alertMessageContents.length > 0) {
197            return true;
198        } else {
199            return false;
200        }
201    },
202
203    isExistErrorMessageWithScreenError : function() {
204        var alertMessageContents = $('.alertMessageContent');
205        if (alertMessageContents.length > 0) {
206            return true;
207        } else {
208            return false;
209        }
210    },
211
212    focusToFirstErrorElement : function() {
213        var alertMessageContents = this.getAlertMessageContents();
214        if (alertMessageContents.length == 0) {
215            return false;
216        }
217
218        for (var i = 0; i < alertMessageContents.length; i++) {
219            var alertMessageContent = alertMessageContents[0];
220            var alertMessageContentParent = alertMessageContent.parentNode;
221            if (isNullorUndefined(alertMessageContentParent)) {
222                continue;
223            }
224
225            var alertMessageContentParentId = alertMessageContentParent.id;
226            if (isNullorUndefinedorEmpty(alertMessageContentParentId)) {
227                continue;
228            }
229
230            var targetFocusId = alertMessageContentParentId.replace(new RegExp("^" + this.errorId), "");
231            focusToItem(targetFocusId);
232            return true;
233        }
234        return false;
235    },
236
237    tohalf : function(str) {
238        if (str == null || str == undefined || str == "") {
239            return "";
240        }
241
242        var half = str.replace(/[A-Za-z0-9]/g, function(s) {
243            return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
244        });
245
246        half = half.replace(/./g, ".");
247        half = half.replace(/[ー-]/g, "-");
248        half = half.replace(/:/g, ":");
249
250        return half;
251    }
252};
253
254Validator.rule = {
255    msg : null,
256
257    submit : function() {
258        return this.msg.submit;
259    },
260
261    input : function() {
262        if (this.field.type == 'radio' || this.field.type == 'checkbox') {
263            for (var i = 0, e; ; i++) {
264                e = this.field.form[this.field.name][i];
265                if (e == null || e == undefined) {
266                    break;
267                }
268                if (e.checked) {
269                    return;
270                }
271            }
272            // 単一チェックボックスの場合の判定
273            var singleChecked = this.field.form[this.field.name].checked;
274            if (singleChecked != null && singleChecked != undefined && singleChecked) {
275                return;
276            }
277            return this.msg.noselect;
278        } else if (this.value == '') {
279            return (this.field.type == 'select-one' || this.field.type == 'select-multiple') ? this.msg.noselect
280                    : this.msg.noinput;
281        }
282    },
283
284    mail: function() {
285        this.tohalf();
286        this.toLower();
287        if (!this.value.match(/^([0-9A-Za-z\-+/~?#=&`{}_]+(\.[0-9A-Za-z\-+/~?#=&`{}_]+)*)@(?:[0-9A-Za-z]+(?:[-.][0-9A-Za-z]+)*\.[0-9A-Za-z]+(?:[-.][0-9A-Za-z]+)*)$/)) {
288            return this.msg.mail;
289        }
290    },
291
292    equal : function() {
293        if (this.field.form[this.extra].value
294                && this.value != this.field.form[this.extra].value) {
295            return this.msg.unequal;
296        }
297    },
298
299    alphabet : function() {
300        this.tohalf();
301        if (!this.value.match(/^[a-zA-Z]+$/)) {
302            return this.msg.alphabet;
303        }
304    },
305
306    alphabet_with_camma : function() {
307        this.tohalf();
308        if (!this.value.match(/^[a-zA-Z,]+$/)) {
309            return this.msg.alphabet;
310        }
311    },
312
313    alphabetNumber : function() {
314        this.tohalf();
315        if (!this.value.match(/^[\x01-\x7F]+$/)) {
316            return this.msg.alphabetNumber;
317        }
318    },
319
320    kana : function() {
321        for (var i = 0; i < this.value.length; i++) {
322            if (this.value.charAt(i) == ' ' || this.value.charAt(i) == '\u3000'){
323                continue;
324            }
325            if ((this.value.charAt(i) < '\u30A1'
326                    || this.value.charAt(i) > '\u30F6') && this.value.charAt(i) !== '\u30FC') {
327                return this.msg.kana;
328            }
329        }
330    },
331
332    hiragana : function() {
333        if (!this.value.match(/^[ぁ-ん0-9A-Za-zー ]*$/)) {
334            return this.msg.hiragana;
335        }
336    },
337
338    zenkaku : function() {
339        if (!this.value.match(/^[0-9A-Za-zぁ-んァ-ヶ一-龠々-ー()  ヽヾゝゞ〆・]*$/)) {
340            return this.msg.zenkaku;
341        }
342    },
343
344    tel : function() {
345        if (!this.value.match(/^\d{2,5}-\d{1,4}-\d{3,4}$/) || !this.value.match(/^[\d-]{12,13}$/)) {
346            return this.msg.tel;
347        }
348    },
349
350    zip : function() {
351        if (!this.value.match(/^[\d]{3}\-[\d]{4}$/)) {
352            return this.msg.zip;
353        }
354    },
355
356    password : function() {
357        if (!this.value.match(/^[A-Za-z0-9`'\)|\+\{_=:\?\[@!\(\]\$>*-\}&<^;/~,"\.#%\\]*$/)) {
358            return this.msg.password;
359        }
360    },
361
362    count : function(arg) {
363        return this._range(arg, this.value.length, this.msg.count);
364    },
365
366    num : function(arg) {
367        this.tohalf();
368        if (!this.value.match(/^[\d,\.-]+$/)) {
369            return this.msg.num.nonumber;
370        }
371        // カンマを外す
372        var number = this.value.replace(/,/g, "");
373        return this._range(arg, parseFloat(number), this.msg.num);
374    },
375
376    numCount : function(arg) {
377        // カンマを外す
378        var number = this.value.replace(/,/g, "");
379        // 小数点以下をスプリット
380        number = number.split("\.")[0];
381        // マイナスは桁数に数えない
382        number = number.replace(/-/g, "");
383        return this._range(arg, number.length, this.msg.numCount);
384    },
385
386    check : function(arg) {
387        var value = 0;
388        for ( var i = 0, e; e = this.field.form[this.field.name][i]; i++){
389            if (e.checked) {
390                value += 1;
391            }
392        }
393
394        return this._range(arg, value, this.msg.check);
395    },
396
397    tohalf : function() {
398        var half = Validator.tohalf(this.value);
399        this.field.value = half;
400        this.value = half;
401    },
402
403    _range : function(range, value, msg) {
404        if (!range)
405            return;
406
407        var result = '';
408        var c = (" " + range).split(/:/);
409
410        var isSetMin = true;
411        var min = parseFloat(c[0]);
412        if (min.toString() == "NaN") {
413            isSetMin = false;
414        }
415
416        var isSetMax = true;
417        var max = parseFloat(c[1]);
418        if (max.toString() == "NaN") {
419            isSetMax = false;
420        }
421        if (isSetMin && value != min && /^\d+$/.test(range)) {
422            result = msg.unequal;
423        } else if (!isSetMin && value > max) {
424            result = msg.too_big;
425        } else if (!isSetMax && value < min) {
426            result = msg.too_small;
427        } else if (isSetMin && isSetMax && (value < min || value > max)) {
428            result = msg.outofrange;
429        }
430        return result.replace(/%1/g, min).replace(/%2/g, max);
431    },
432
433    toLower : function() {
434        // 全て小文字に変換
435        var inputText = this.value;
436        this.value = inputText.toLowerCase();
437        this.field.value = inputText.toLowerCase();
438    }
439};
440
441Validator.lang = {
442    ja : {
443        noselect : '必須選択項目です。選択してください。',
444        noinput : '必須入力項目です。入力してください。',
445        unequal : '入力が揃っていません。',
446
447        submit : 'エラーがあります。',
448        mail : '正しい形式のメールアドレスを入力してください。',
449        alphabet : '半角のアルファベットを入力してください。',
450        alphabetNumber : '半角の英数文字を入力してください。',
451        kana : '全角カタカナで入力してください。',
452        hiragana : 'ひらがなを入力してください。',
453        zenkaku : '全角文字を入力してください。',
454        tel : '正しい形式の電話番号を入力してください。',
455        zip : '正しい形式の郵便番号を入力してください。',
456        password : '正しい形式のパスワードを入力してください。',
457        birthday : '生年月日を入力してください。',
458
459        count : {
460            unequal : '%1' + '文字で入力してください。',
461            too_big : '%2' + '文字以下で入力してください。',
462            too_small : '%1' + '文字以上で入力してください。',
463            outofrange : '%1' + '文字以上' + '%2' + '文字以下で入力してください。'
464        },
465
466        num : {
467            nonumber : '数値を入力してください。',
468            unequal : '%1' + 'と入力してください。',
469            too_big : '%2' + '以下の値を入力してください。',
470            too_small : '%1' + '以上の値を入力してください。',
471            outofrange : '%1' + 'から' + '%2' + 'の間で入力してください。'
472        },
473
474        numCount : {
475            unequal : '%1' + '桁の値を入力してください。',
476            too_big : '%2' + '桁以下の値を入力してください。',
477            too_small : '%1' + '桁以上の値を入力してください。',
478            outofrange : '%1' + '桁以上' + '%2' + '桁以下で入力してください。'
479        },
480
481        check : {
482            unequal : 'チェックは' + '%1' + '個してください。',
483            too_big : 'チェックは' + '%2' + '個までです。',
484            too_small : 'チェックは' + '%1' + '個以上してください。',
485            outofrange : 'チェックは' + '%1' + '個から' + '%2' + '個までです。'
486        },
487
488        date : {
489            nodate : '正しい日付を入力してください。',
490            notime : '正しい時刻を入力してください。',
491            input_yyyymm : 'yyyy/MM の形式で入力してください。',
492            input_yyyymmdd : 'yyyy/MM/dd の形式で入力してください。',
493            input_yyyymmddhhmm : 'yyyy/MM/dd HH:mm の形式で入力してください。',
494            input_yyyymmddhhmmss : 'yyyy/MM/dd HH:mm:ss の形式で入力してください。',
495            input_yyyymmddhhmmsssss : 'yyyy/MM/dd HH:mm:ss sss の形式で入力してください。',
496            input_hhmm : 'hh:mm の形式で入力してください。'
497        },
498
499        others : {
500            cleditor_init : '入力が不正のため正しく表示できません。ソースモードで確認してください。'
501        }
502    }
503
504//    ,en : {
505//        noselect : '',
506//        noinput : '',
507//        unequal : '',
508//
509//        submit : 'exists error.',
510//        mail : '',
511//        alphabet : '',
512//        alphabetNumber : '',
513//        kana : '',
514//        zenkaku : '',
515//        tel : '',
516//        zip : '',
517//        password : '',
518//        birthday : '',
519//
520//        count : {
521//            unequal : '%1' + '',
522//            too_big : '%2' + '',
523//            too_small : '%1' + '',
524//            outofrange : '%1' + '' + '%2' + ''
525//        },
526//
527//        num : {
528//            nonumber : '',
529//            unequal : '%1' + '',
530//            too_big : '%2' + '',
531//            too_small : '%1' + '',
532//            outofrange : '%1' + '' + '%2' + ''
533//        },
534//
535//        numCount : {
536//            unequal : '%1' + '',
537//            too_big : '%2' + '',
538//            too_small : '%1' + '',
539//            outofrange : '%1' + '' + '%2' + ''
540//        },
541//
542//        check : {
543//            unequal : '' + '%1' + '',
544//            too_big : '' + '%2' + '',
545//            too_small : '' + '%1' + '',
546//            outofrange : '' + '%1' + '' + '%2' + ''
547//        },
548//
549//        date : {
550//            nodate : '',
551//            notime : '',
552//            input_yyyymm : 'yyyy/MM',
553//            input_yyyymmdd : 'yyyy/MM/dd',
554//            input_yyyymmddhhmm : 'yyyy/MM/dd HH:mm',
555//            input_yyyymmddhhmmss : 'yyyy/MM/dd HH:mm:ss',
556//            input_yyyymmddhhmmsssss : 'yyyy/MM/dd HH:mm:ss sss',
557//            input_hhmm : 'hh:mm'
558//        }
559//    }
560};
561
562Validator.rule.msg = Validator.lang.ja;

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.