js如何提取匹配文章中的手機和電話號碼?微信小程序vuejs

 

const content = "我的手機是13123456789,我的電話是022-12345678"
const phone = []
if (content.match(/1(3|4|5|7|8)\d{9}/g) || content.match(/0[0-9]{2,3}-\d{8,9}/g)) {
    const arr1 = content.match(/1(3|4|5|7|8)\d{9}/g)
    const arr2 = content.match(/0[0-9]{2,3}-\d{8,9}/g)
    phone.push(...arr1,...arr2)
}
console.log(phone) // ["13123456789","022-12345678"]

 

微信小程序開發交流qq羣   829873465

承接微信小程序開發,掃碼加微信

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章