var formatePhoneNumber = function (phoneText) { phoneText = phoneText.replace(/(^\s*)|(\s*$)/g, ‘‘);//trim var phoneArr; var maxPhoneNumberLength = 24; var formattedPhoneText; //remove first 0 if (phoneText) { phoneArr = phoneText.split(‘‘); if (phoneArr[0] == ‘0‘) { phoneArr.splice(0, 1); } else if (phoneArr[0] == ‘(‘ && phoneArr.length > 1 && phoneArr[1] == ‘0‘) { phoneArr.splice(1, 1); } } phoneText=phoneArr.join(‘‘).replace(/[\D]/g, ‘‘); //get only number if (phoneText) { } function phoneNumberFormater(validation, formate, display,len) { this.validationExp = validation; this.formatExp = formate; this.displayFormat = display; this.extensionDelimiter = " x. "; this.numberLength = len; } phoneNumberFormater.prototype.validatePhoneNumber = function () { }; phoneNumberFormater.prototype.isMatchDisplayingFormat = function () { }; phoneNumberFormater.prototype.formatePhoneNumber = function (phoneNumber) { var formattedPhoneText = ""; var i = 0; for (var c in this.displayFormat) { if (c == ‘#‘) { formattedPhoneText += phoneNumber[i]; i++; } else { formattedPhoneText += c; } } if (phoneNumber.length > this.numberLength) { formattedPhoneText += this.extensionDelimiter + phoneNumber.substr(this.numberLength); } return formattedPhoneText; }; var phoneNumberFormatInfo2_WithExtension=new phoneNumberFormater(); var phoneNumberFormatInfo3_WithExtension=new phoneNumberFormater(); var phoneNumberFormatInfo4_WithExtension=new phoneNumberFormater(); var phoneNumberFormatInfo5=new phoneNumberFormater(); var phoneNumberFormatInfo6=new phoneNumberFormater(); var phoneNumberFormatInfo7=new phoneNumberFormater(); var phoneNumberFormatInfo8=new phoneNumberFormater(); var phoneNumberFormatInfo11 = new phoneNumberFormater(); var defaultPhoneNumberFormatList = []; if (formattedPhoneText && formattedPhoneText[0] != ‘0‘) { formattedPhoneText=formattedPhoneText.split(‘‘); if (formattedPhoneText[0] != ‘(‘) { formattedPhoneText.splice(0,0,‘0‘); } else if (formattedPhoneText.length > 1 && formattedPhoneText[1] != ‘0‘) { formattedPhoneText.splice(1,0,‘0‘); } } formattedPhoneText=formattedPhoneText.join(‘‘).replace(/[\s\(\)]/g, ‘‘); }
时间: 2024-10-15 00:25:48