-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtr-input.min.js
More file actions
1 lines (1 loc) · 3.6 KB
/
Copy pathtr-input.min.js
File metadata and controls
1 lines (1 loc) · 3.6 KB
1
!function(t){var F=function(){};F.prototype={phoneRule:function(F){var e=new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);return e.test(t(F).val())?(console.log("表单验证通过"),t(F).nextAll().length&&t(F).parent().find(".text-danger").text(""),!0):(t(F).nextAll().length?t(F).parent().find(".text-danger").text("表单验证不通过"):t(F).empty().after('<div class="text-danger">表单验证不通过</div>'),!1)},emailRule:function(e){var u=t(e).val(),n=u.toLowerCase().split("@"),a=n[0],r=n[1];if(a&&r){if(0===a.indexOf('"')){var l=a.length;if(a=a.replace(/\"/g,""),a.length!==l-2)return!1}return console.log("trInput.prototype.validatorFunction(emailParts[1]",F.prototype.validatorFunction(n[1])),void(F.prototype.validatorFunction(n[1])&&0!==a.indexOf(".")&&"."!==a.substring(a.length-1,a.length)&&a.indexOf("..")===-1&&!/[^\w\+\.\-\#\-\_\~\!\$\&\'\(\)\*\+\,\;\=\:]/.test(a)&&t(e).nextAll().length&&t(e).parent().find(".text-danger").text(""))}t(e).nextAll().length?t(e).parent().find(".text-danger").text("表单验证不通过"):t(e).empty().after('<div class="text-danger">表单验证不通过</div>')},urlRule:function(e){var u=t(e).val(),n=/^(https?|ftp):\/\/((((\w|-|\.|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])(\w|-|\.|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])(\w|-|\.|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/(((\w|-|\.|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/((\w|-|\.|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|\[|\]|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#(((\w|-|\.|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;if(n.test(u)){var a=u.split("://")[1],r=a.indexOf("/");return r>-1&&(a=a.substr(0,r)),!!F.prototype.validatorFunction(a)&&(t(e).nextAll().length&&t(e).parent().find(".text-danger").text(""),!0)}t(e).nextAll().length?t(e).parent().find(".text-danger").text("表单验证不通过"):t(e).empty().after('<div class="text-danger">表单验证不通过</div>')},Validator:function(F,e,u,n){e(F)?u[n]="pass":u[n]="failed",t(F).on("blur",function(){e(F)?u[n]="pass":u[n]="failed"})},validatorFunction:function(t){return t.length>0&&t.length<=253&&!/[^a-zA-Z0-9]/.test(t.slice(-2))&&!/[^a-zA-Z0-9]/.test(t.substr(0,1))&&!/[^a-zA-Z0-9\.\-]/.test(t)&&1===t.split("..").length&&t.split(".").length>1}},t.fn.trInput=function(){var e=this,u=[];e.form=t("body").find("form"),t.map(e.form,function(e){var n=t(e).find("input[tr-valid],textarea[tr-valid]");t(e).on("submit",function(){t.map(n,function(e,n){switch(t(e).attr("tr-valid")){case"phone":F.prototype.Validator(e,F.prototype.phoneRule,u,n);break;case"email":F.prototype.Validator(e,F.prototype.emailRule,u,n);break;case"url":F.prototype.Validator(e,F.prototype.urlRule,u,n)}});for(var e=setInterval(function(){for(var t=0;t<u.length;t++)if("failed"==u[t])return!1;if(u.length==n.length)return clearInterval(e),!0},100),a=0;a<u.length;a++)if("failed"==u[a])return!1})})}}(jQuery),$("body").trInput();