/* ================================================================ * ajaxzip3.js ---- AjaxZip3 郵便番号→住所変換ライブラリ Copyright (c) 2008-2015 Ninkigumi Co.,Ltd. http://ajaxzip3.github.io/ Copyright (c) 2006-2007 Kawasaki Yusuke http://www.kawa.net/works/ajax/AjaxZip2/AjaxZip2.html Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ================================================================ */ AjaxZip3=function(){};AjaxZip3.VERSION="0.51";AjaxZip3.JSONDATA="https://yubinbango.github.io/yubinbango-data/data";AjaxZip3.CACHE=[];AjaxZip3.prev="";AjaxZip3.nzip="";AjaxZip3.fzip1="";AjaxZip3.fzip2="";AjaxZip3.fpref="";AjaxZip3.addr="";AjaxZip3.fstrt="";AjaxZip3.farea="";AjaxZip3.ffocus=true;AjaxZip3.onSuccess=null;AjaxZip3.onFailure=null;AjaxZip3.PREFMAP=[null,"北海道","青森県","岩手県","宮城県","秋田県","山形県","福島県","茨城県","栃木県","群馬県","埼玉県","千葉県","東京都","神奈川県","新潟県","富山県","石川県","福井県","山梨県","長野県","岐阜県","静岡県","愛知県","三重県","滋賀県","京都府","大阪府","兵庫県","奈良県","和歌山県","鳥取県","島根県","岡山県","広島県","山口県","徳島県","香川県","愛媛県","高知県","福岡県","佐賀県","長崎県","熊本県","大分県","宮崎県","鹿児島県","沖縄県"];AjaxZip3.zip2addr=function(h,g,k,b,l,a,m){AjaxZip3.fzip1=AjaxZip3.getElementByName(h);AjaxZip3.fzip2=AjaxZip3.getElementByName(g,AjaxZip3.fzip1);AjaxZip3.fpref=AjaxZip3.getElementByName(k,AjaxZip3.fzip1);AjaxZip3.faddr=AjaxZip3.getElementByName(b,AjaxZip3.fzip1);AjaxZip3.fstrt=AjaxZip3.getElementByName(a,AjaxZip3.fzip1);AjaxZip3.farea=AjaxZip3.getElementByName(l,AjaxZip3.fzip1);AjaxZip3.ffocus=m===undefined?true:m;if(!AjaxZip3.fzip1){return}if(!AjaxZip3.fpref){return}if(!AjaxZip3.faddr){return}var c=AjaxZip3.fzip1.value;if(AjaxZip3.fzip2&&AjaxZip3.fzip2.value){c+=AjaxZip3.fzip2.value}if(!c){return}AjaxZip3.nzip="";for(var f=0;f57){continue}AjaxZip3.nzip+=c.charAt(f)}if(AjaxZip3.nzip.length<7){return}var j=function(){var i=AjaxZip3.nzip+AjaxZip3.fzip1.name+AjaxZip3.fpref.name+AjaxZip3.faddr.name;if(AjaxZip3.fzip1.form){i+=AjaxZip3.fzip1.form.id+AjaxZip3.fzip1.form.name+AjaxZip3.fzip1.form.action}if(AjaxZip3.fzip2){i+=AjaxZip3.fzip2.name}if(AjaxZip3.fstrt){i+=AjaxZip3.fstrt.name}if(i==AjaxZip3.prev){return}AjaxZip3.prev=i};var n=AjaxZip3.nzip.substr(0,3);var e=AjaxZip3.CACHE[n];if(e){return AjaxZip3.callback(e)}AjaxZip3.zipjsonpquery()};AjaxZip3.callback=function(h){function d(){if(typeof AjaxZip3.onFailure==="function"){AjaxZip3.onFailure()}}var m=h[AjaxZip3.nzip];var e=(AjaxZip3.nzip-0+4278190080)+"";if(!m&&h[e]){m=h[e]}if(!m){d();return}var b=m[0];if(!b){d();return}var o=AjaxZip3.PREFMAP[b];if(!o){d();return}var c=m[1];if(!c){c=""}var r=m[2];if(!r){r=""}var f=m[3];if(!f){f=""}var q=AjaxZip3.faddr;var k=c;if(AjaxZip3.fpref.type=="select-one"||AjaxZip3.fpref.type=="select-multiple"){var a=AjaxZip3.fpref.options;for(var g=0;g-1){var a=escape(c);if(a.indexOf("%u")<0&&a.indexOf("%")>-1){c=decodeURIComponent(a)}}return c};AjaxZip3.getElementByName=function(d,b){if(typeof(d)=="string"){var e=document.getElementsByName(d);if(!e){return null}if(e.length>1&&b&&b.form){var c=b.form.elements;for(var a=0;a").attr("name",c.submitButton.name).val(a(c.submitButton).val()).appendTo(c.currentForm)),!c.settings.submitHandler||(e=c.settings.submitHandler.call(c,c.currentForm,b),d&&d.remove(),void 0!==e&&e)}return c.settings.debug&&b.preventDefault(),c.cancelSubmit?(c.cancelSubmit=!1,d()):c.form()?c.pendingRequest?(c.formSubmitted=!0,!1):d():(c.focusInvalid(),!1)})),c)},valid:function(){var b,c,d;return a(this[0]).is("form")?b=this.validate().form():(d=[],b=!0,c=a(this[0].form).validate(),this.each(function(){b=c.element(this)&&b,b||(d=d.concat(c.errorList))}),c.errorList=d),b},rules:function(b,c){var d,e,f,g,h,i,j=this[0];if(null!=j&&(!j.form&&j.hasAttribute("contenteditable")&&(j.form=this.closest("form")[0],j.name=this.attr("name")),null!=j.form)){if(b)switch(d=a.data(j.form,"validator").settings,e=d.rules,f=a.validator.staticRules(j),b){case"add":a.extend(f,a.validator.normalizeRule(c)),delete f.messages,e[j.name]=f,c.messages&&(d.messages[j.name]=a.extend(d.messages[j.name],c.messages));break;case"remove":return c?(i={},a.each(c.split(/\s/),function(a,b){i[b]=f[b],delete f[b]}),i):(delete e[j.name],f)}return g=a.validator.normalizeRules(a.extend({},a.validator.classRules(j),a.validator.attributeRules(j),a.validator.dataRules(j),a.validator.staticRules(j)),j),g.required&&(h=g.required,delete g.required,g=a.extend({required:h},g)),g.remote&&(h=g.remote,delete g.remote,g=a.extend(g,{remote:h})),g}}}),a.extend(a.expr.pseudos||a.expr[":"],{blank:function(b){return!a.trim(""+a(b).val())},filled:function(b){var c=a(b).val();return null!==c&&!!a.trim(""+c)},unchecked:function(b){return!a(b).prop("checked")}}),a.validator=function(b,c){this.settings=a.extend(!0,{},a.validator.defaults,b),this.currentForm=c,this.init()},a.validator.format=function(b,c){return 1===arguments.length?function(){var c=a.makeArray(arguments);return c.unshift(b),a.validator.format.apply(this,c)}:void 0===c?b:(arguments.length>2&&c.constructor!==Array&&(c=a.makeArray(arguments).slice(1)),c.constructor!==Array&&(c=[c]),a.each(c,function(a,c){b=b.replace(new RegExp("\\{"+a+"\\}","g"),function(){return c})}),b)},a.extend(a.validator,{defaults:{messages:{},groups:{},rules:{},errorClass:"error",pendingClass:"pending",validClass:"valid",errorElement:"label",focusCleanup:!1,focusInvalid:!0,errorContainer:a([]),errorLabelContainer:a([]),onsubmit:!0,ignore:":hidden",ignoreTitle:!1,onfocusin:function(a){this.lastActive=a,this.settings.focusCleanup&&(this.settings.unhighlight&&this.settings.unhighlight.call(this,a,this.settings.errorClass,this.settings.validClass),this.hideThese(this.errorsFor(a)))},onfocusout:function(a){this.checkable(a)||!(a.name in this.submitted)&&this.optional(a)||this.element(a)},onkeyup:function(b,c){var d=[16,17,18,20,35,36,37,38,39,40,45,144,225];9===c.which&&""===this.elementValue(b)||a.inArray(c.keyCode,d)!==-1||(b.name in this.submitted||b.name in this.invalid)&&this.element(b)},onclick:function(a){a.name in this.submitted?this.element(a):a.parentNode.name in this.submitted&&this.element(a.parentNode)},highlight:function(b,c,d){"radio"===b.type?this.findByName(b.name).addClass(c).removeClass(d):a(b).addClass(c).removeClass(d)},unhighlight:function(b,c,d){"radio"===b.type?this.findByName(b.name).removeClass(c).addClass(d):a(b).removeClass(c).addClass(d)}},setDefaults:function(b){a.extend(a.validator.defaults,b)},messages:{required:"This field is required.",remote:"Please fix this field.",email:"Please enter a valid email address.",url:"Please enter a valid URL.",date:"Please enter a valid date.",dateISO:"Please enter a valid date (ISO).",number:"Please enter a valid number.",digits:"Please enter only digits.",equalTo:"Please enter the same value again.",maxlength:a.validator.format("Please enter no more than {0} characters."),minlength:a.validator.format("Please enter at least {0} characters."),rangelength:a.validator.format("Please enter a value between {0} and {1} characters long."),range:a.validator.format("Please enter a value between {0} and {1}."),max:a.validator.format("Please enter a value less than or equal to {0}."),min:a.validator.format("Please enter a value greater than or equal to {0}."),step:a.validator.format("Please enter a multiple of {0}.")},autoCreateRanges:!1,prototype:{init:function(){function b(b){!this.form&&this.hasAttribute("contenteditable")&&(this.form=a(this).closest("form")[0],this.name=a(this).attr("name"));var c=a.data(this.form,"validator"),d="on"+b.type.replace(/^validate/,""),e=c.settings;e[d]&&!a(this).is(e.ignore)&&e[d].call(c,this,b)}this.labelContainer=a(this.settings.errorLabelContainer),this.errorContext=this.labelContainer.length&&this.labelContainer||a(this.currentForm),this.containers=a(this.settings.errorContainer).add(this.settings.errorLabelContainer),this.submitted={},this.valueCache={},this.pendingRequest=0,this.pending={},this.invalid={},this.reset();var c,d=this.groups={};a.each(this.settings.groups,function(b,c){"string"==typeof c&&(c=c.split(/\s/)),a.each(c,function(a,c){d[c]=b})}),c=this.settings.rules,a.each(c,function(b,d){c[b]=a.validator.normalizeRule(d)}),a(this.currentForm).on("focusin.validate focusout.validate keyup.validate",":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], [type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], [type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], [type='radio'], [type='checkbox'], [contenteditable], [type='button']",b).on("click.validate","select, option, [type='radio'], [type='checkbox']",b),this.settings.invalidHandler&&a(this.currentForm).on("invalid-form.validate",this.settings.invalidHandler)},form:function(){return this.checkForm(),a.extend(this.submitted,this.errorMap),this.invalid=a.extend({},this.errorMap),this.valid()||a(this.currentForm).triggerHandler("invalid-form",[this]),this.showErrors(),this.valid()},checkForm:function(){this.prepareForm();for(var a=0,b=this.currentElements=this.elements();b[a];a++)this.check(b[a]);return this.valid()},element:function(b){var c,d,e=this.clean(b),f=this.validationTargetFor(e),g=this,h=!0;return void 0===f?delete this.invalid[e.name]:(this.prepareElement(f),this.currentElements=a(f),d=this.groups[f.name],d&&a.each(this.groups,function(a,b){b===d&&a!==f.name&&(e=g.validationTargetFor(g.clean(g.findByName(a))),e&&e.name in g.invalid&&(g.currentElements.push(e),h=g.check(e)&&h))}),c=this.check(f)!==!1,h=h&&c,c?this.invalid[f.name]=!1:this.invalid[f.name]=!0,this.numberOfInvalids()||(this.toHide=this.toHide.add(this.containers)),this.showErrors(),a(b).attr("aria-invalid",!c)),h},showErrors:function(b){if(b){var c=this;a.extend(this.errorMap,b),this.errorList=a.map(this.errorMap,function(a,b){return{message:a,element:c.findByName(b)[0]}}),this.successList=a.grep(this.successList,function(a){return!(a.name in b)})}this.settings.showErrors?this.settings.showErrors.call(this,this.errorMap,this.errorList):this.defaultShowErrors()},resetForm:function(){a.fn.resetForm&&a(this.currentForm).resetForm(),this.invalid={},this.submitted={},this.prepareForm(),this.hideErrors();var b=this.elements().removeData("previousValue").removeAttr("aria-invalid");this.resetElements(b)},resetElements:function(a){var b;if(this.settings.unhighlight)for(b=0;a[b];b++)this.settings.unhighlight.call(this,a[b],this.settings.errorClass,""),this.findByName(a[b].name).removeClass(this.settings.validClass);else a.removeClass(this.settings.errorClass).removeClass(this.settings.validClass)},numberOfInvalids:function(){return this.objectLength(this.invalid)},objectLength:function(a){var b,c=0;for(b in a)void 0!==a[b]&&null!==a[b]&&a[b]!==!1&&c++;return c},hideErrors:function(){this.hideThese(this.toHide)},hideThese:function(a){a.not(this.containers).text(""),this.addWrapper(a).hide()},valid:function(){return 0===this.size()},size:function(){return this.errorList.length},focusInvalid:function(){if(this.settings.focusInvalid)try{a(this.findLastActive()||this.errorList.length&&this.errorList[0].element||[]).filter(":visible").focus().trigger("focusin")}catch(b){}},findLastActive:function(){var b=this.lastActive;return b&&1===a.grep(this.errorList,function(a){return a.element.name===b.name}).length&&b},elements:function(){var b=this,c={};return a(this.currentForm).find("input, select, textarea, [contenteditable]").not(":submit, :reset, :image, :disabled").not(this.settings.ignore).filter(function(){var d=this.name||a(this).attr("name");return!d&&b.settings.debug&&window.console&&console.error("%o has no name assigned",this),this.hasAttribute("contenteditable")&&(this.form=a(this).closest("form")[0],this.name=d),!(d in c||!b.objectLength(a(this).rules()))&&(c[d]=!0,!0)})},clean:function(b){return a(b)[0]},errors:function(){var b=this.settings.errorClass.split(" ").join(".");return a(this.settings.errorElement+"."+b,this.errorContext)},resetInternals:function(){this.successList=[],this.errorList=[],this.errorMap={},this.toShow=a([]),this.toHide=a([])},reset:function(){this.resetInternals(),this.currentElements=a([])},prepareForm:function(){this.reset(),this.toHide=this.errors().add(this.containers)},prepareElement:function(a){this.reset(),this.toHide=this.errorsFor(a)},elementValue:function(b){var c,d,e=a(b),f=b.type;return"radio"===f||"checkbox"===f?this.findByName(b.name).filter(":checked").val():"number"===f&&"undefined"!=typeof b.validity?b.validity.badInput?"NaN":e.val():(c=b.hasAttribute("contenteditable")?e.text():e.val(),"file"===f?"C:\\fakepath\\"===c.substr(0,12)?c.substr(12):(d=c.lastIndexOf("/"),d>=0?c.substr(d+1):(d=c.lastIndexOf("\\"),d>=0?c.substr(d+1):c)):"string"==typeof c?c.replace(/\r/g,""):c)},check:function(b){b=this.validationTargetFor(this.clean(b));var c,d,e,f,g=a(b).rules(),h=a.map(g,function(a,b){return b}).length,i=!1,j=this.elementValue(b);if("function"==typeof g.normalizer?f=g.normalizer:"function"==typeof this.settings.normalizer&&(f=this.settings.normalizer),f){if(j=f.call(b,j),"string"!=typeof j)throw new TypeError("The normalizer should return a string value.");delete g.normalizer}for(d in g){e={method:d,parameters:g[d]};try{if(c=a.validator.methods[d].call(this,j,b,e.parameters),"dependency-mismatch"===c&&1===h){i=!0;continue}if(i=!1,"pending"===c)return void(this.toHide=this.toHide.not(this.errorsFor(b)));if(!c)return this.formatAndAdd(b,e),!1}catch(k){throw this.settings.debug&&window.console&&console.log("Exception occurred when checking element "+b.id+", check the '"+e.method+"' method.",k),k instanceof TypeError&&(k.message+=". Exception occurred when checking element "+b.id+", check the '"+e.method+"' method."),k}}if(!i)return this.objectLength(g)&&this.successList.push(b),!0},customDataMessage:function(b,c){return a(b).data("msg"+c.charAt(0).toUpperCase()+c.substring(1).toLowerCase())||a(b).data("msg")},customMessage:function(a,b){var c=this.settings.messages[a];return c&&(c.constructor===String?c:c[b])},findDefined:function(){for(var a=0;aWarning: No message defined for "+b.name+""),e=/\$?\{(\d+)\}/g;return"function"==typeof d?d=d.call(this,c.parameters,b):e.test(d)&&(d=a.validator.format(d.replace(e,"{$1}"),c.parameters)),d},formatAndAdd:function(a,b){var c=this.defaultMessage(a,b);this.errorList.push({message:c,element:a,method:b.method}),this.errorMap[a.name]=c,this.submitted[a.name]=c},addWrapper:function(a){return this.settings.wrapper&&(a=a.add(a.parent(this.settings.wrapper))),a},defaultShowErrors:function(){var a,b,c;for(a=0;this.errorList[a];a++)c=this.errorList[a],this.settings.highlight&&this.settings.highlight.call(this,c.element,this.settings.errorClass,this.settings.validClass),this.showLabel(c.element,c.message);if(this.errorList.length&&(this.toShow=this.toShow.add(this.containers)),this.settings.success)for(a=0;this.successList[a];a++)this.showLabel(this.successList[a]);if(this.settings.unhighlight)for(a=0,b=this.validElements();b[a];a++)this.settings.unhighlight.call(this,b[a],this.settings.errorClass,this.settings.validClass);this.toHide=this.toHide.not(this.toShow),this.hideErrors(),this.addWrapper(this.toShow).show()},validElements:function(){return this.currentElements.not(this.invalidElements())},invalidElements:function(){return a(this.errorList).map(function(){return this.element})},showLabel:function(b,c){var d,e,f,g,h=this.errorsFor(b),i=this.idOrName(b),j=a(b).attr("aria-describedby");h.length?(h.removeClass(this.settings.validClass).addClass(this.settings.errorClass),h.html(c)):(h=a("<"+this.settings.errorElement+">").attr("id",i+"-error").addClass(this.settings.errorClass).html(c||""),d=h,this.settings.wrapper&&(d=h.hide().show().wrap("<"+this.settings.wrapper+"/>").parent()),this.labelContainer.length?this.labelContainer.append(d):this.settings.errorPlacement?this.settings.errorPlacement.call(this,d,a(b)):d.insertAfter(b),h.is("label")?h.attr("for",i):0===h.parents("label[for='"+this.escapeCssMeta(i)+"']").length&&(f=h.attr("id"),j?j.match(new RegExp("\\b"+this.escapeCssMeta(f)+"\\b"))||(j+=" "+f):j=f,a(b).attr("aria-describedby",j),e=this.groups[b.name],e&&(g=this,a.each(g.groups,function(b,c){c===e&&a("[name='"+g.escapeCssMeta(b)+"']",g.currentForm).attr("aria-describedby",h.attr("id"))})))),!c&&this.settings.success&&(h.text(""),"string"==typeof this.settings.success?h.addClass(this.settings.success):this.settings.success(h,b)),this.toShow=this.toShow.add(h)},errorsFor:function(b){var c=this.escapeCssMeta(this.idOrName(b)),d=a(b).attr("aria-describedby"),e="label[for='"+c+"'], label[for='"+c+"'] *";return d&&(e=e+", #"+this.escapeCssMeta(d).replace(/\s+/g,", #")),this.errors().filter(e)},escapeCssMeta:function(a){return a.replace(/([\\!"#$%&'()*+,.\/:;<=>?@\[\]^`{|}~])/g,"\\$1")},idOrName:function(a){return this.groups[a.name]||(this.checkable(a)?a.name:a.id||a.name)},validationTargetFor:function(b){return this.checkable(b)&&(b=this.findByName(b.name)),a(b).not(this.settings.ignore)[0]},checkable:function(a){return/radio|checkbox/i.test(a.type)},findByName:function(b){return a(this.currentForm).find("[name='"+this.escapeCssMeta(b)+"']")},getLength:function(b,c){switch(c.nodeName.toLowerCase()){case"select":return a("option:selected",c).length;case"input":if(this.checkable(c))return this.findByName(c.name).filter(":checked").length}return b.length},depend:function(a,b){return!this.dependTypes[typeof a]||this.dependTypes[typeof a](a,b)},dependTypes:{"boolean":function(a){return a},string:function(b,c){return!!a(b,c.form).length},"function":function(a,b){return a(b)}},optional:function(b){var c=this.elementValue(b);return!a.validator.methods.required.call(this,c,b)&&"dependency-mismatch"},startRequest:function(b){this.pending[b.name]||(this.pendingRequest++,a(b).addClass(this.settings.pendingClass),this.pending[b.name]=!0)},stopRequest:function(b,c){this.pendingRequest--,this.pendingRequest<0&&(this.pendingRequest=0),delete this.pending[b.name],a(b).removeClass(this.settings.pendingClass),c&&0===this.pendingRequest&&this.formSubmitted&&this.form()?(a(this.currentForm).submit(),this.submitButton&&a("input:hidden[name='"+this.submitButton.name+"']",this.currentForm).remove(),this.formSubmitted=!1):!c&&0===this.pendingRequest&&this.formSubmitted&&(a(this.currentForm).triggerHandler("invalid-form",[this]),this.formSubmitted=!1)},previousValue:function(b,c){return c="string"==typeof c&&c||"remote",a.data(b,"previousValue")||a.data(b,"previousValue",{old:null,valid:!0,message:this.defaultMessage(b,{method:c})})},destroy:function(){this.resetForm(),a(this.currentForm).off(".validate").removeData("validator").find(".validate-equalTo-blur").off(".validate-equalTo").removeClass("validate-equalTo-blur")}},classRuleSettings:{required:{required:!0},email:{email:!0},url:{url:!0},date:{date:!0},dateISO:{dateISO:!0},number:{number:!0},digits:{digits:!0},creditcard:{creditcard:!0}},addClassRules:function(b,c){b.constructor===String?this.classRuleSettings[b]=c:a.extend(this.classRuleSettings,b)},classRules:function(b){var c={},d=a(b).attr("class");return d&&a.each(d.split(" "),function(){this in a.validator.classRuleSettings&&a.extend(c,a.validator.classRuleSettings[this])}),c},normalizeAttributeRule:function(a,b,c,d){/min|max|step/.test(c)&&(null===b||/number|range|text/.test(b))&&(d=Number(d),isNaN(d)&&(d=void 0)),d||0===d?a[c]=d:b===c&&"range"!==b&&(a[c]=!0)},attributeRules:function(b){var c,d,e={},f=a(b),g=b.getAttribute("type");for(c in a.validator.methods)"required"===c?(d=b.getAttribute(c),""===d&&(d=!0),d=!!d):d=f.attr(c),this.normalizeAttributeRule(e,g,c,d);return e.maxlength&&/-1|2147483647|524288/.test(e.maxlength)&&delete e.maxlength,e},dataRules:function(b){var c,d,e={},f=a(b),g=b.getAttribute("type");for(c in a.validator.methods)d=f.data("rule"+c.charAt(0).toUpperCase()+c.substring(1).toLowerCase()),this.normalizeAttributeRule(e,g,c,d);return e},staticRules:function(b){var c={},d=a.data(b.form,"validator");return d.settings.rules&&(c=a.validator.normalizeRule(d.settings.rules[b.name])||{}),c},normalizeRules:function(b,c){return a.each(b,function(d,e){if(e===!1)return void delete b[d];if(e.param||e.depends){var f=!0;switch(typeof e.depends){case"string":f=!!a(e.depends,c.form).length;break;case"function":f=e.depends.call(c,c)}f?b[d]=void 0===e.param||e.param:(a.data(c.form,"validator").resetElements(a(c)),delete b[d])}}),a.each(b,function(d,e){b[d]=a.isFunction(e)&&"normalizer"!==d?e(c):e}),a.each(["minlength","maxlength"],function(){b[this]&&(b[this]=Number(b[this]))}),a.each(["rangelength","range"],function(){var c;b[this]&&(a.isArray(b[this])?b[this]=[Number(b[this][0]),Number(b[this][1])]:"string"==typeof b[this]&&(c=b[this].replace(/[\[\]]/g,"").split(/[\s,]+/),b[this]=[Number(c[0]),Number(c[1])]))}),a.validator.autoCreateRanges&&(null!=b.min&&null!=b.max&&(b.range=[b.min,b.max],delete b.min,delete b.max),null!=b.minlength&&null!=b.maxlength&&(b.rangelength=[b.minlength,b.maxlength],delete b.minlength,delete b.maxlength)),b},normalizeRule:function(b){if("string"==typeof b){var c={};a.each(b.split(/\s/),function(){c[this]=!0}),b=c}return b},addMethod:function(b,c,d){a.validator.methods[b]=c,a.validator.messages[b]=void 0!==d?d:a.validator.messages[b],c.length<3&&a.validator.addClassRules(b,a.validator.normalizeRule(b))},methods:{required:function(b,c,d){if(!this.depend(d,c))return"dependency-mismatch";if("select"===c.nodeName.toLowerCase()){var e=a(c).val();return e&&e.length>0}return this.checkable(c)?this.getLength(b,c)>0:b.length>0},email:function(a,b){return this.optional(b)||/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(a)},url:function(a,b){return this.optional(b)||/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[\/?#]\S*)?$/i.test(a)},date:function(a,b){return this.optional(b)||!/Invalid|NaN/.test(new Date(a).toString())},dateISO:function(a,b){return this.optional(b)||/^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(a)},number:function(a,b){return this.optional(b)||/^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(a)},digits:function(a,b){return this.optional(b)||/^\d+$/.test(a)},minlength:function(b,c,d){var e=a.isArray(b)?b.length:this.getLength(b,c);return this.optional(c)||e>=d},maxlength:function(b,c,d){var e=a.isArray(b)?b.length:this.getLength(b,c);return this.optional(c)||e<=d},rangelength:function(b,c,d){var e=a.isArray(b)?b.length:this.getLength(b,c);return this.optional(c)||e>=d[0]&&e<=d[1]},min:function(a,b,c){return this.optional(b)||a>=c},max:function(a,b,c){return this.optional(b)||a<=c},range:function(a,b,c){return this.optional(b)||a>=c[0]&&a<=c[1]},step:function(b,c,d){var e,f=a(c).attr("type"),g="Step attribute on input type "+f+" is not supported.",h=["text","number","range"],i=new RegExp("\\b"+f+"\\b"),j=f&&!i.test(h.join()),k=function(a){var b=(""+a).match(/(?:\.(\d+))?$/);return b&&b[1]?b[1].length:0},l=function(a){return Math.round(a*Math.pow(10,e))},m=!0;if(j)throw new Error(g);return e=k(d),(k(b)>e||l(b)%l(d)!==0)&&(m=!1),this.optional(c)||m},equalTo:function(b,c,d){var e=a(d);return this.settings.onfocusout&&e.not(".validate-equalTo-blur").length&&e.addClass("validate-equalTo-blur").on("blur.validate-equalTo",function(){a(c).valid()}),b===e.val()},remote:function(b,c,d,e){if(this.optional(c))return"dependency-mismatch";e="string"==typeof e&&e||"remote";var f,g,h,i=this.previousValue(c,e);return this.settings.messages[c.name]||(this.settings.messages[c.name]={}),i.originalMessage=i.originalMessage||this.settings.messages[c.name][e],this.settings.messages[c.name][e]=i.message,d="string"==typeof d&&{url:d}||d,h=a.param(a.extend({data:b},d.data)),i.old===h?i.valid:(i.old=h,f=this,this.startRequest(c),g={},g[c.name]=b,a.ajax(a.extend(!0,{mode:"abort",port:"validate"+c.name,dataType:"json",data:g,context:f.currentForm,success:function(a){var d,g,h,j=a===!0||"true"===a;f.settings.messages[c.name][e]=i.originalMessage,j?(h=f.formSubmitted,f.resetInternals(),f.toHide=f.errorsFor(c),f.formSubmitted=h,f.successList.push(c),f.invalid[c.name]=!1,f.showErrors()):(d={},g=a||f.defaultMessage(c,{method:e,parameters:b}),d[c.name]=i.message=g,f.invalid[c.name]=!0,f.showErrors(d)),i.valid=j,f.stopRequest(c,j)}},d)),"pending")}}});var b,c={};return a.ajaxPrefilter?a.ajaxPrefilter(function(a,b,d){var e=a.port;"abort"===a.mode&&(c[e]&&c[e].abort(),c[e]=d)}):(b=a.ajax,a.ajax=function(d){var e=("mode"in d?d:a.ajaxSettings).mode,f=("port"in d?d:a.ajaxSettings).port;return"abort"===e?(c[f]&&c[f].abort(),c[f]=b.apply(this,arguments),c[f]):b.apply(this,arguments)}),a});// function debounce(func, wait, immediate) { // var timeout; // return function() { // var context = this, // args = arguments; // var later = function() { // timeout = null; // if (!immediate) func.apply(context, args); // }; // var callNow = immediate && !timeout; // clearTimeout(timeout); // timeout = setTimeout(later, wait); // if (callNow) func.apply(context, args); // }; // }; // function recaptchaCallback() { // var response = grecaptcha.getResponse(), // $button = jQuery(".confirm"); // jQuery("#hidden-grecaptcha").val(response); // console.log(jQuery("#contactForm").valid()); // // if (jQuery("#contactForm").valid()) { // // $button.attr("disabled", false); // // } else { // // $button.attr("disabled", "disabled"); // // } // } // function recaptchaExpired() { // var $button = jQuery(".confirm"); // jQuery("#hidden-grecaptcha").val(""); // // var $button = jQuery(".confirm"); // // if (jQuery("#contactForm").valid()) { // // $button.attr("disabled", false); // // } else { // // $button.attr("disabled", "disabled"); // // } // } jQuery().ready(function() { // jQuery("#contactForm").find("input").on("keyup", debounce(function() { // // var $button = jQuery(".button-register"); // // console.log(jQuery("#registerForm").valid()); // // if (jQuery("#registerForm").valid()) { // // $button.attr("disabled", false); // // } else { // // $button.attr("disabled", "disabled"); // // } // }, 1000)); jQuery("#contactForm").validate({ groups: { address1: "post_zip01 post_zip02", user_name01: "post_name_last post_name_first", user_name02: "post_name_last_kana post_name_first_kana", address2: "post1 post2", user_name03: "jfamname jfstname", user_name04: "kfamname kfstname", post_birthday: "post_birthday_year post_birthday_month post_birthday_day", post_education01: "post_education01 post_education02", product_purchase: "product_purchase_year product_purchase_month product_purchase_day", product_inspection: "product_inspection_year product_inspection_month product_inspection_day", post_inspection: "post_inspection_year post_inspection_month post_inspection_day", product_purchase_1: "product_purchase_year_1 product_purchase_month_1 product_purchase_day_1", product_inspection_1: "product_inspection_year_1 product_inspection_month_1 product_inspection_day_1", product_purchase_2: "product_purchase_year_2 product_purchase_month_2 product_purchase_day_2", product_inspection_2: "product_inspection_year_2 product_inspection_month_2 product_inspection_day_2", product_purchase_3: "product_purchase_year_3 product_purchase_month_3 product_purchase_day_3", product_inspection_3: "product_inspection_year_3 product_inspection_month_3 product_inspection_day_3", product_purchase_4: "product_purchase_year_4 product_purchase_month_4 product_purchase_day_4", product_inspection_4: "product_inspection_year_4 product_inspection_month_4 product_inspection_day_4", product_purchase_5: "product_purchase_year_5 product_purchase_month_5 product_purchase_day_5", product_inspection_5: "product_inspection_year_5 product_inspection_month_5 product_inspection_day_5", product_purchase_6: "product_purchase_year_6 product_purchase_month_6 product_purchase_day_6", product_inspection_6: "product_inspection_year_6 product_inspection_month_6 product_inspection_day_6", product_purchase_7: "product_purchase_year_7 product_purchase_month_7 product_purchase_day_7", product_inspection_7: "product_inspection_year_7 product_inspection_month_7 product_inspection_day_7", product_purchase_8: "product_purchase_year_8 product_purchase_month_8 product_purchase_day_8", product_inspection_8: "product_inspection_year_8 product_inspection_month_8 product_inspection_day_8", product_purchase_9: "product_purchase_year_9 product_purchase_month_9 product_purchase_day_9", product_inspection_9: "product_inspection_year_9 product_inspection_month_9 product_inspection_day_9", product_purchase_10: "product_purchase_year_10 product_purchase_month_10 product_purchase_day_10", product_inspection_10: "product_inspection_year_10 product_inspection_month_10 product_inspection_day_10", }, rules: { 'desired_company': { }, 'desired_job': { }, 'post_name_last': { required: true, }, 'post_name_first': { required: true, }, 'post_name_last_kana': { required: true,hiragana: true }, 'post_name_first_kana': { required: true,hiragana: true }, 'post_birthday_year': { required: true, }, 'post_birthday_month': { required: true, }, 'post_birthday_day': { required: true, }, 'post_education01': { required: true, }, 'post_education02': { required: true, }, 'post_graduation': { }, 'post_prefectures': { }, 'post_tel': { required: true,telnum2: true, }, 'post_email': { required: true,email: true, }, 'post_email_kakunin': { required: true,equalTo: "#post_email",email: true, }, 'post_method': { }, 'post_comment': { }, 'privacy': { required: true, }, "hidden-grecaptcha": { required: true, minlength: "255" } }, messages: { 'desired_company': { }, 'desired_job': { }, 'post_name_last': { required: "「お名前」は必須入力です。", }, 'post_name_first': { required: "「お名前」は必須入力です。", }, 'post_name_last_kana': { required: "「ふりがな」は必須入力です。", }, 'post_name_first_kana': { required: "「ふりがな」は必須入力です。", }, 'post_birthday_year': { required: "「生年月日」は必須選択です。", }, 'post_birthday_month': { required: "「生年月日」は必須選択です。", }, 'post_birthday_day': { required: "「生年月日」は必須選択です。", }, 'post_education01': { required: "「最終学歴」は必須選択です。", }, 'post_education02': { required: "「最終学歴」は必須入力です。", }, 'post_graduation': { }, 'post_prefectures': { }, 'post_tel': { required: "「電話番号」は必須入力です。", }, 'post_email': { required: "「メールアドレス」は必須入力です。", }, 'post_email_kakunin': { required: "「メールアドレス確認用」は必須入力です。",equalTo: "「メールアドレス」が一致しません。", }, 'post_method': { }, 'post_comment': { }, 'privacy': { required: "「トミー精工個人情報のお取り扱いについて」は必須入力です。",required: "個人情報の取り扱いについて同意していただいてから確認画面へお進みください。", }, "hidden-grecaptcha": { required: "あなたがロボットでないことを確認してください。", } }, errorContainer: ".error-text", errorClass: "error", errorElement: "p", highlight: function(element, errorClass) {}, errorPlacement: function(error, element) { if (element.attr("name") === "privacy") { // error.insertAfter('#address1'); element.parents(".entry-footer-item").append(error); // error.insertAfter(element.parents(".entry-footer-item")); } else if (element.attr("name") === "hidden-grecaptcha") { error.insertAfter(element); } else if(document.URL.match("/admin")) { if (element.parents(".col-4.row").length) { element.parents(".col-4.row").append(error); } else if (element.parents(".col-3.row").length) { element.parents(".col-3.row").append(error); } else if (element.parents(".col-6").length) { element.parents(".col-6").append(error); } else{ error.insertAfter(element); } } else { // element.parents(".form-wapper-item").append(error); error.insertAfter(element.parents(".entry-box")); } } }); jQuery("#post_tel,#post_fax,#tel,#fax").change(function() { var txt = jQuery(this).val(); var han = txt.replace(/[A-Za-z0-9]/g, function(s) { return String.fromCharCode(s.charCodeAt(0) - 0xFEE0) }); han = han.replace(/‐/g, "-"); han = han.replace(/―/g, "-"); han = han.replace(/-/g, "-"); han = han.replace(/\(/g, "("); han = han.replace(/\)/g, ")"); jQuery(this).val(han) }); jQuery("#post_email,#post_email_kakunin,#email,#email_kakunin").change(function() { var txt = jQuery(this).val(); var han = txt.replace(/[A-Za-z0-9 @.]/g, function(s) { return String.fromCharCode(s.charCodeAt(0) - 0xFEE0) }); han = han.replace(/‐/g, "-"); han = han.replace(/―/g, "-"); han = han.replace(/-/g, "-"); jQuery(this).val(han) }); jQuery("#post_zip01,#post_zip02").change(function() { var txt = jQuery(this).val(); var han = txt.replace(/[0-9]/g, function(s) { return String.fromCharCode(s.charCodeAt(0) - 0xFEE0) }); han = han.replace(/‐/g, "-"); han = han.replace(/―/g, "-"); han = han.replace(/-/g, "-"); jQuery(this).val(han); AjaxZip3.zip2addr('post_zip01', 'post_zip02', 'post_prefectures', 'post_address'); }); jQuery("#post1,#post2").change(function() { var txt = jQuery(this).val(); var han = txt.replace(/[0-9]/g, function(s) { return String.fromCharCode(s.charCodeAt(0) - 0xFEE0) }); han = han.replace(/‐/g, "-"); han = han.replace(/―/g, "-"); han = han.replace(/-/g, "-"); jQuery(this).val(han); AjaxZip3.zip2addr('post1', 'post2', 'pref', 'addr'); }); jQuery('#post_birthday_year, #post_birthday_month').change(function() { formSetDay(); }); }); function formSetDay() { var lastday = formSetLastDay(jQuery('#post_birthday_year').val(), jQuery('#post_birthday_month').val()); var option = ''; for (var i = 1; i <= lastday; i++) { if (i == jQuery('#post_birthday_day').val()) { option += '\n'; } else { option += '\n'; } } jQuery('#post_birthday_day').html(option); } function formSetLastDay(year, month) { var lastday = new Array('', 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) { lastday[2] = 29; } return lastday[month]; } jQuery.extend(jQuery.validator.messages, { required: "必須項目です", maxlength: jQuery.validator.format("{0} 文字以下を入力してください。"), minlength: jQuery.validator.format("{0} 文字以上を入力してください。"), rangelength: jQuery.validator.format("{0} 文字以上 {1} 文字以下で入力してください。"), email: "メールアドレスを入力してください。", url: "URLを入力してください。", dateISO: "日付を入力してください。", number: "有効な数字を入力してください。", digits: "0-9までを入力してください。", equalTo: "同じ値を入力してください。", range: jQuery.validator.format(" {0} から {1} までの値を入力してください。"), max: jQuery.validator.format("{0} 以下の値を入力してください。"), min: jQuery.validator.format("{0} 以上の値を入力してください。"), creditcard: "クレジットカード番号を入力してください。" }); //全角ひらがな・カタカナのみ jQuery.validator.addMethod("kana", function(value, element) { return this.optional(element) || /^([ァ-ヶーぁ-ん]+)$/.test(value) }, "全角ひらがな・カタカナを入力してください。"); //全角ひらがなのみ jQuery.validator.addMethod("hiragana", function(value, element) { return this.optional(element) || /^([ぁ-ん  ]+)$/.test(value) }, "全角ひらがなを入力してください。"); //全角カタカナのみ jQuery.validator.addMethod("katakana", function(value, element) { return this.optional(element) || /^([ァ-ヶー  ]+)$/.test(value) }, "全角カタカナを入力してください。"); //半角カタカナのみ jQuery.validator.addMethod("hankana", function(value, element) { return this.optional(element) || /^([ァ-ン゙゚]+)$/.test(value) }, "半角カタカナを入力してください。"); //全半角カタカナのみ jQuery.validator.addMethod("katakana2", function(value, element) { return this.optional(element) || /^([ァ-ヶーァ-ン゙゚  ]+)$/.test(value) }, "カタカナを入力してください。"); //半角アルファベット(大文字・小文字)のみ jQuery.validator.addMethod("alphabet", function(value, element) { return this.optional(element) || /^([a-zA-z\s]+)$/.test(value) }, "半角英字を入力してください。"); //半角アルファベット(大文字・小文字)もしくは数字のみ jQuery.validator.addMethod("alphanum", function(value, element) { return this.optional(element) || /^([a-zA-Z0-9]+)$/.test(value) }, "半角英数字を入力してください。"); //郵便番号(例:012-3456) jQuery.validator.addMethod("postnum", function(value, element) { return this.optional(element) || /^\d{3}\-\d{4}$/.test(value) }, "郵便番号を入力してください。(例:123-4567)"); jQuery.validator.addMethod("postnum2", function(value, element) { return this.optional(element) || /^\d{3}$/.test(value) }, "郵便番号を入力してください。(例:123-4567)"); jQuery.validator.addMethod("postnum3", function(value, element) { return this.optional(element) || /^\d{4}$/.test(value) }, "郵便番号を入力してください。(例:123-4567)"); //携帯番号(例:010-2345-6789) jQuery.validator.addMethod("mobilenum", function(value, element) { return this.optional(element) || /^0\d0-\d{4}-\d{4}$/.test(value) }, "携帯番号を入力してください。(例:010-2345-6789)"); //電話番号(例:012-345-6789) jQuery.validator.addMethod("telnum", function(value, element) { return this.optional(element) || /^[0-9-]{10,12}$/.test(value) }, "電話番号を入力してください。(例:012-345-6789)"); //電話番号(例:012-345-6789) jQuery.validator.addMethod("telnum2", function(value, element) { return this.optional(element) || /^0\d{1,4}[-(]?\d{1,4}[-)]?\d{3,4}[()内線ex.0-9]+$/.test(value) }, "電話番号を入力してください。(例:012-345-6789)"); $.validator.addMethod('notDuplicate', function(value, element, param) { if ($(element).val() === '') { return true; } var that = this; var bool = true; $(param).each(function() { if (element === $(this).get(0)) { // 自身との同一チェックは行わない return true; } bool = bool && !$.validator.methods.equalTo.call(that, value, element, this); }); return this.optional(element) || bool; }, '「ID」が重複しています。');