手机号码处理为344格式
2017-07-18 16:57
1581 查看
// 去掉字符串中所有空格(包括中间空格,需要设置第2个参数为:g) function trim(str, is_global) { var result; result = str.replace(/(^\s+)|(\s+$)/g, ""); if (is_global && is_global.toLowerCase() == "g") { result = result.replace(/\s/g, ""); } return result; } // 判断是否是手机号码格式 function isPhone(str) { var reg = /^1(3|4|5|7|8)\d{9}$/; return reg.test(trim(str, 'g')); } // 手机号码格式转化为 344 格式 (188 3886 9199) function phoneSeparated(phoneNumber) { let tel = trim(phoneNumber, 'g'); if (isPhone(tel)) { tel = tel.substring(0, 3) + ' ' + tel.substring(3, 7) + ' ' + tel.substring(7, 11); } return tel; } phoneSeparated("18838869199") // "188 3886 9199"
相关文章推荐
- 手机号码格式化;实现手机号344格式输入:000 0000 0000
- iOS 手机号码格式化,344格式
- easyUI 验证控件应用、自定义、扩展验证 手机号码或电话话码格式
- 2.手机号码格式校验
- 验证手机号码格式的正则表达式编写思路详解
- js正则表达式:验证邮箱格式、密码复杂度、手机号码、QQ号码(转)
- js正则表达式用法实例:验证邮箱格式、密码复杂度、手机号码、QQ号码
- JS验证手机号码格式
- easyUI 验证控件应用、自定义、扩展验证 手机号码或电话话码格式
- 手机号码格式和邮箱格式校正
- Android 手机号码格式验证
- android edittext 输入手机号码格式变化
- 手机号码格式验证
- 判断手机号码格式、身份证号码格式是否正确
- iOS 手机号码格式检测
- js正则表达式——验证邮箱格式、邮编、身份证号码、是否为空、下拉框选项、密码、手机号码、电话号码
- 验证手机号码格式
- ASP用正则验证邮箱地址手机号码电话号码格式
- ios利用正则表达式判断手机号码格式是否正确的实例
- js正则表达式:验证邮箱格式、密码复杂度、手机号码、QQ号码(未测试)