iPhone 输入

    /**
     * 手机号码每四位加入一个空格
     * @param phone 手机号码
     * @returns {string}
     */
    formatPhoneWithSpace (phone : any) {
        if (!phone) return '';
        phone = phone.toString();
        phone = phone.replace(/\s*/g, '');
        const result = [];
        for (let i = 0; i < phone.length; i++) {
            if (i === 3 || i === 7) {
                result.push(' ' + phone.charAt(i));
            } else {
                result.push(phone.charAt(i));
            }
        }
        phone = result.join('');

        return phone;
    }

你可能感兴趣的:(iPhone 输入)