把 validatePhone(...) 集成入 i18n-lands.js

This commit is contained in:
Luk Lu
2023-01-31 19:07:36 +08:00
parent 419b8b4eda
commit e0408f5000
3 changed files with 23 additions and 44 deletions

19
i18n.js
View File

@@ -3,23 +3,4 @@ module.exports = {
landSet: require('./i18n-lands.js'),
currencySet: require('./i18n-currencies.js'),
cryptocoinSet: require('./i18n-cryptocoins.js'),
validatePhone ({ phone } = {}) {
try {
let [fullphone, areacode, callnumber] = /^\+(\d{1,3})-(\d{7,11})$/.exec(phone)
switch (areacode) {
case this.landSet['CN'].itc:
return /^1\d{10}$/.test(callnumber)
case this.landSet['SG'].itc:
return /^[89]\d{7}$/.test(callnumber)
case this.landSet['US'].itc:
return /^\d{10}$/.test(callnumber)
case this.landSet['JP'].itc:
return /^\d{10}$/.test(callnumber)
default:
return true
}
} catch (err) {
return false
}
},
}