PageSourceSearch

https://www.nikkenhomes.co.jp/wp/wp-content/themes/nikkenhomes_202…/js/email-normalize.js?ver=260914063336

js nikkenhomes.co.jp collected 2026-09-29 16:40:54 UTC 2,703 bytes, 65 lines download raw bytes

1/**
2 * email-normalize.js — メール入力欄の空白除去(全フォーム共通)
3 *
4 * 背景:
5 *   モバイルのメール候補(サジェスト)をタップして入力すると、末尾スペースや
6 *   非改行スペース(U+00A0)・全角スペース(U+3000)が混入することがある。
7 *   CF7 6.x のクライアント側検証(SWV)や type="email" のネイティブ検証は
8 *   前後・途中の空白を許容せず(かつクライアント側は trim しない)、その場で弾く。
9 *   手入力はクリーンな値なので通る、という差になっていた。
10 *
11 * 方針:
12 *   メールアドレスに空白は含まれないため、input[type="email"] の値から
13 *   すべての空白文字を除去して正規化する。CF7・ネイティブ検証の手前で値を
14 *   きれいにし、送信データにも空白を残さない。
15 *
16 * 対象:
17 *   nh_is_form_page_2026()(総合お問い合わせ/資料請求/採用応募/来場予約)で読み込む。
18 *   入力途中は邪魔しないよう blur / paste / submit の時だけ正規化する。
19 */
20(function () {
21  'use strict';
22
23  var WS = /[\s  ]/g; // 半角/改行/タブ + 全角スペース + NBSP
24
25  function normalize(el) {
26    if (!el || typeof el.value !== 'string') return;
27    var cleaned = el.value.replace(WS, '');
28    if (cleaned !== el.value) {
29      el.value = cleaned;
30      // 送信ボタンの活性判定(form-2026.js)や CF7 の状態を更新
31      el.dispatchEvent(new Event('input', { bubbles: true }));
32      el.dispatchEvent(new Event('change', { bubbles: true }));
33    }
34  }
35
36  function bind(el) {
37    el.addEventListener('blur', function () { normalize(el); });
38    // 貼り付けは確定後に処理
39    el.addEventListener('paste', function () {
40      window.setTimeout(function () { normalize(el); }, 0);
41    });
42  }
43
44  function init() {
45    var emails = document.querySelectorAll('input[type="email"]');
46    for (var i = 0; i < emails.length; i++) {
47      bind(emails[i]);
48    }
49    // 送信直前にも念のため正規化(blur を経ずに送信されるケースの保険)。
50    // capture フェーズで CF7 のハンドラより先に走らせる。
51    var forms = document.querySelectorAll('form');
52    for (var j = 0; j < forms.length; j++) {
53      forms[j].addEventListener('submit', function (e) {
54        var list = e.currentTarget.querySelectorAll('input[type="email"]');
55        for (var k = 0; k < list.length; k++) { normalize(list[k]); }
56      }, true);
57    }
58  }
59
60  if (document.readyState === 'loading') {
61    document.addEventListener('DOMContentLoaded', init);
62  } else {
63    init();
64  }
65})();

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.