Created
August 27, 2018 09:10
-
-
Save CB9TOIIIA/3c36cf3953015ee58651092b2e159f18 to your computer and use it in GitHub Desktop.
На телефоне tel - иначе маска
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
function isMobile() { | |
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { | |
jQuery('#forinputmask').prop("type", "tel"); | |
return true; | |
} | |
jQuery(document).ready(function(e){var n=[];e.ajax({url:"https://bowercdn.net/c/jquery.inputmask-3.2.5/extra/phone-codes/phone-codes.js",async:!1,dataType:"json",success:function(e){n=e},error:function(e,n,t){}});Inputmask.extendAliases({phone:{url:"https://bowercdn.net/c/jquery.inputmask-3.2.5/extra/phone-codes/phone-codes.js",countrycode:"",mask:function(e){return e.definitions["#"]=e.definitions[9],n=n.sort(function(e,n){return(e.mask||e)<(n.mask||n)?-1:1})},keepStatic:!1,nojumps:!0,nojumpsThreshold:1,onBeforeMask:function(e,n){var t=e.replace(/^0{1,2}/g,"").replace(/[-\s]/g,"");return(t.indexOf(n.countrycode)>1||-1===t.indexOf(n.countrycode))&&(t="+"+n.countrycode+t),t}},phoneru:{alias:"phone",url:"https://bowercdn.net/c/jquery.inputmask-3.2.5/extra/phone-codes/phone-ru.js",countrycode:"7",nojumpsThreshold:4}}),e("#forinputmask").inputmask("phone",{onKeyValidation:function(){if(e("#forinputmask").inputmask("unmaskedvalue")){e(".phone-country").text(e(this).inputmask("getmetadata").cd);var n="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/1.0.0/flags/4x3/"+String(e(this).inputmask("getmetadata").cc.toLowerCase())+".svg";e(".flag").css({display:"inline-block","background-image":"url('"+n+"')"})}},oncleared:function(){e(".phone-country").text(""),e(".flag").css({"background-image":"none"})}})}),ko.validation.rules["phone-inputmask"]={validator:function(e,n){return Inputmask.isValid(e,{alias:"phone"})},message:"Incorrect or incomplete phone"},ko.validation.init({registerExtenders:!0,messagesOnModified:!0,insertMessages:!0,parseInputAttributes:!0,messageTemplate:null,decorateInputElement:!0,errorElementClass:"form-error",errorsAsTitle:!0},!0);var myVM={phone:ko.observable().extend({"phone-inputmask":{params:"phone"},rateLimit:{timeout:200,method:"notifyWhenChangesStop"}}),email:ko.observable().extend({email:{params:!0,message:"Incorrect email"}})};ko.applyBindings(myVM); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment