码迷,mamicode.com
首页 > 其他好文 > 详细

phonelist

时间:2015-06-04 06:10:35      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

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, ‘‘);
}

  

phonelist

标签:

原文地址:http://www.cnblogs.com/yfann/p/4550769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!