$(function(){ //必須項目のチェック $('.requiredItem').on('blur', function() { $(this).next('p.error').remove(); // この要素の後続要素を削除 if( $(this).val() !== '' ) return; $(this).after('

必須項目です。入力をお願いします。

'); // この要素の後にエラーメッセージを挿入 $(".error").show("slow"); }); //▼メールアドレス形式のチェック $('#email').on('blur', function() { var error = false; var mail_regex1 = new RegExp( '(?:[-!#-\'*+/-9=?A-Z^-~]+\.?(?:\.[-!#-\'*+/-9=?A-Z^-~]+)*|"(?:[!#-\[\]-~]|\\\\[\x09 -~])*")@[-!#-\'*+/-9=?A-Z^-~]+(?:\.[-!#-\'*+/-9=?A-Z^-~]+)*' ); var mail_regex2 = new RegExp( '^[^\@]+\@[^\@]+$' ); if( $(this).val().match( mail_regex1 ) && $(this).val().match( mail_regex2 ) ) { // 全角チェック if( $(this).val().match( /[^a-zA-Z0-9\!\"\#\$\%\&\'\(\)\=\~\|\-\^\\\@\[\;\:\]\,\.\/\\\<\>\?\_\`\{\+\*\} ]/ ) ) { error = true; } // 末尾TLDチェック(〜.co,jpなどの末尾ミスチェック用) if( !$(this).val().match( /\.[a-z]+$/ ) ) { error = true; } error = false; } else { error = true; } if(error) { if(!$(this).next('p.error').length) { $(this).after('

メールアドレスの形式で入力して下さい。

'); $(".error").show("slow"); } } else { // エラーがなかった場合 $(this).next('p.error').remove(); // この要素の後続要素を削除 } }); //▼電話番号形式のチェック $('#phone').on('blur', function() { $(this).next('p.error').remove(); if( $(this).val().replace(/[━.*‐.*―.*-.*\-.*ー.*\-]/gi,'').match( /^(0[5-9]0[0-9]{8}|0[1-9][1-9][0-9]{7})$/ ) || $(this).val() === '') return; $(this).after('

電話番号の形式で入力して下さい。

'); $(".error").show("slow"); }); // $('.formEntryItem').on('click blur', checkEntry ); $("#sendBtn").on('click', function(){ $('#formContent').submit(); }); });//END function /* submitクリック前のチェック*/ var checkEntry = function() { if( $('#name').val() !== '' && $('#email').val() !== '' && $('#subject').val() !== '' && !$('#email').next('p.error').length && !$('#phone').next('p.error').length && $('#check').prop('checked') ) { $('#sendBtn').prop('disabled', false); } else { $('#sendBtn').prop('disabled', true); } }; $(window).on('load', checkEntry );