1 changed files with 119 additions and 88 deletions
@ -1,99 +1,130 @@ |
|||||
// 手机正则
|
// 手机正则
|
||||
export function reg(params1,params2){ |
export function reg(params1, params2) { |
||||
let phone = '' |
let phone = '' |
||||
let code = '' |
let code = '' |
||||
|
|
||||
let ret = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/ // 手机正则
|
let ret = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/ // 手机正则
|
||||
let intPattern = /^[0-9]*$/ // 整数正则
|
let intPattern = /^[0-9]*$/ // 整数正则
|
||||
|
|
||||
if(params1 === ''){ |
if (params1 === '') { |
||||
uni.showToast({title:'请输入手机号',icon:"none"}) |
uni.showToast({ |
||||
}else if( !ret.test(params1) ){ |
title: '请输入手机号', |
||||
|
icon: "none" |
||||
|
}) |
||||
|
} else if (!ret.test(params1)) { |
||||
console.log(params1) |
console.log(params1) |
||||
uni.showToast({title:'手机号不正确',icon:"none"}) |
uni.showToast({ |
||||
}else if(params2 === 0){ |
title: '手机号不正确', |
||||
uni.showToast({title:'获取验证码',icon:"none"}) |
icon: "none" |
||||
}else if( params2 === '' ){ |
}) |
||||
uni.showToast({title:'请输入验证码',icon:"none"}) |
} else if (params2 === 0) { |
||||
}else if( params2 !== 0 && !intPattern.test(params2) ){ |
uni.showToast({ |
||||
uni.showToast({title:'验证码不正确',icon:"none"}) |
title: '获取验证码', |
||||
}else if( params2 !== 0 && intPattern.test(params2)){ |
icon: "none" |
||||
|
}) |
||||
|
} else if (params2 === '') { |
||||
|
uni.showToast({ |
||||
|
title: '请输入验证码', |
||||
|
icon: "none" |
||||
|
}) |
||||
|
} else if (params2 !== 0 && !intPattern.test(params2)) { |
||||
|
uni.showToast({ |
||||
|
title: '验证码不正确', |
||||
|
icon: "none" |
||||
|
}) |
||||
|
} else if (params2 !== 0 && intPattern.test(params2)) { |
||||
phone = ret |
phone = ret |
||||
code = intPattern |
code = intPattern |
||||
}else{ |
} else { |
||||
phone = ret |
phone = ret |
||||
code = intPattern |
code = intPattern |
||||
} |
} |
||||
|
|
||||
return phone,code |
|
||||
} |
|
||||
/** |
|
||||
* 省市区、自治区分割 |
|
||||
*/ |
|
||||
export function getArea(str) { |
|
||||
let area = {}; //最终返回的地址
|
|
||||
let un_pro_str = ''; //去掉省以后的地址
|
|
||||
let un_city_str = ''; //去掉市以后的地址
|
|
||||
|
|
||||
// 第一个区域(省)截取开始
|
|
||||
let _dominion = str.indexOf("自治区"); //自治区出现的位置(内蒙古自治区、广西壮族自治区、西藏自治区、宁夏回族自治区、新疆维吾尔自治区、)
|
|
||||
let _district = str.indexOf('行政区'); //特别行政区出现的位置(香港特别行政区、澳门特别行政区)
|
|
||||
let _province = str.indexOf("省"); //省出现的位置
|
|
||||
let _city = str.indexOf('市'); //市出现的位置(北京市、天津市、上海市、重庆市)
|
|
||||
if (_dominion != -1) { //有自治区
|
|
||||
area.province = str.substring(0, _dominion + 3) |
|
||||
un_pro_str = str.substr(_dominion + 3); |
|
||||
} else if (_province != -1) { //有省
|
|
||||
area.province = str.substring(0, _province + 1) |
|
||||
un_pro_str = str.substr(_province + 1); |
|
||||
} else if (_district != -1) { //有行政区
|
|
||||
area.province = str.substring(0, _district + 3) |
|
||||
un_pro_str = str.substr(_district + 3); |
|
||||
} else if (_city != -1) { //有市
|
|
||||
area.province = str.substring(0, _city + 1) |
|
||||
un_pro_str = str.substr(_city + 1); |
|
||||
} |
|
||||
console.log('去掉省以后的地址', un_pro_str) |
|
||||
|
|
||||
|
|
||||
// 第二个区域(市)截取开始
|
|
||||
let _city1 = un_pro_str.indexOf('市'); //第二次出现市的位置
|
|
||||
let _district1 = un_pro_str.indexOf('行政区'); //特别行政区出现的位置
|
|
||||
let _county = un_pro_str.indexOf('县'); //县出现的位置
|
|
||||
let _state = un_pro_str.indexOf('自治州'); //自治州出现的位置
|
|
||||
let _region = un_pro_str.indexOf('区'); //区出现的位置
|
|
||||
let _zoning = un_pro_str.indexOf('行政区划'); //行政区划出现的位置
|
|
||||
let _alliance = un_pro_str.indexOf('盟'); //盟出现的位置
|
|
||||
if (_zoning != -1) { //行政区划
|
|
||||
area.city = un_pro_str.substring(0, _zoning + 4) |
|
||||
un_city_str = un_pro_str.substr(_zoning + 4); |
|
||||
} else if (_district1 != -1) { //行政区
|
|
||||
area.city = un_pro_str.substring(0, _district1 + 3) |
|
||||
un_city_str = un_pro_str.substr(_district1 + 3); |
|
||||
} else if (_state != -1) { //自治州
|
|
||||
area.city = un_pro_str.substring(0, _state + 3) |
|
||||
un_city_str = un_pro_str.substr(_state + 3); |
|
||||
} else if (_alliance != -1) { //盟
|
|
||||
area.city = un_pro_str.substring(0, _alliance + 1) |
|
||||
un_city_str = un_pro_str.substr(_alliance + 1); |
|
||||
} else if (_city1 != -1) { //市
|
|
||||
area.city = un_pro_str.substring(0, _city1 + 1) |
|
||||
un_city_str = un_pro_str.substr(_city1 + 1); |
|
||||
} else if (_region != -1) { //区
|
|
||||
area.city = un_pro_str.substring(0, _region + 1) |
|
||||
un_city_str = un_pro_str.substr(_region + 1); |
|
||||
} else if (_county != -1) { //县
|
|
||||
area.city = un_pro_str.substring(0, _county + 1) |
|
||||
un_city_str = un_pro_str.substr(_county + 1); |
|
||||
} |
|
||||
|
|
||||
var reg = /.+?(市|县|区)/g; |
|
||||
var aaa; |
|
||||
aaa = un_city_str.match(reg); |
|
||||
area.country = aaa[0]; |
|
||||
var xiangxi = str.substring(str.indexOf(aaa[0]) + 3) |
|
||||
area.address = xiangxi |
|
||||
|
|
||||
return area; |
|
||||
} |
|
||||
|
|
||||
|
return phone, code |
||||
|
} |
||||
|
//名称脱敏
|
||||
|
export function maskShopName(str) { |
||||
|
var reg = /^(.).+(.)$/g; |
||||
|
if (str != null && str != "") { |
||||
|
if (str.length < 4) { |
||||
|
str = str.replace(reg, "$1*$2"); |
||||
|
} else { |
||||
|
str = str.replace(reg, "$1***$2"); |
||||
|
} |
||||
|
} |
||||
|
console.log('1111111111',str) |
||||
|
return str; |
||||
|
} |
||||
|
//电话脱敏
|
||||
|
export function maskPhone(phone) { |
||||
|
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2'); |
||||
|
} |
||||
|
/** |
||||
|
* 省市区、自治区分割 |
||||
|
*/ |
||||
|
export function getArea(str) { |
||||
|
let area = {}; //最终返回的地址
|
||||
|
let un_pro_str = ''; //去掉省以后的地址
|
||||
|
let un_city_str = ''; //去掉市以后的地址
|
||||
|
|
||||
|
// 第一个区域(省)截取开始
|
||||
|
let _dominion = str.indexOf("自治区"); //自治区出现的位置(内蒙古自治区、广西壮族自治区、西藏自治区、宁夏回族自治区、新疆维吾尔自治区、)
|
||||
|
let _district = str.indexOf('行政区'); //特别行政区出现的位置(香港特别行政区、澳门特别行政区)
|
||||
|
let _province = str.indexOf("省"); //省出现的位置
|
||||
|
let _city = str.indexOf('市'); //市出现的位置(北京市、天津市、上海市、重庆市)
|
||||
|
if (_dominion != -1) { //有自治区
|
||||
|
area.province = str.substring(0, _dominion + 3) |
||||
|
un_pro_str = str.substr(_dominion + 3); |
||||
|
} else if (_province != -1) { //有省
|
||||
|
area.province = str.substring(0, _province + 1) |
||||
|
un_pro_str = str.substr(_province + 1); |
||||
|
} else if (_district != -1) { //有行政区
|
||||
|
area.province = str.substring(0, _district + 3) |
||||
|
un_pro_str = str.substr(_district + 3); |
||||
|
} else if (_city != -1) { //有市
|
||||
|
area.province = str.substring(0, _city + 1) |
||||
|
un_pro_str = str.substr(_city + 1); |
||||
|
} |
||||
|
console.log('去掉省以后的地址', un_pro_str) |
||||
|
|
||||
|
|
||||
|
// 第二个区域(市)截取开始
|
||||
|
let _city1 = un_pro_str.indexOf('市'); //第二次出现市的位置
|
||||
|
let _district1 = un_pro_str.indexOf('行政区'); //特别行政区出现的位置
|
||||
|
let _county = un_pro_str.indexOf('县'); //县出现的位置
|
||||
|
let _state = un_pro_str.indexOf('自治州'); //自治州出现的位置
|
||||
|
let _region = un_pro_str.indexOf('区'); //区出现的位置
|
||||
|
let _zoning = un_pro_str.indexOf('行政区划'); //行政区划出现的位置
|
||||
|
let _alliance = un_pro_str.indexOf('盟'); //盟出现的位置
|
||||
|
if (_zoning != -1) { //行政区划
|
||||
|
area.city = un_pro_str.substring(0, _zoning + 4) |
||||
|
un_city_str = un_pro_str.substr(_zoning + 4); |
||||
|
} else if (_district1 != -1) { //行政区
|
||||
|
area.city = un_pro_str.substring(0, _district1 + 3) |
||||
|
un_city_str = un_pro_str.substr(_district1 + 3); |
||||
|
} else if (_state != -1) { //自治州
|
||||
|
area.city = un_pro_str.substring(0, _state + 3) |
||||
|
un_city_str = un_pro_str.substr(_state + 3); |
||||
|
} else if (_alliance != -1) { //盟
|
||||
|
area.city = un_pro_str.substring(0, _alliance + 1) |
||||
|
un_city_str = un_pro_str.substr(_alliance + 1); |
||||
|
} else if (_city1 != -1) { //市
|
||||
|
area.city = un_pro_str.substring(0, _city1 + 1) |
||||
|
un_city_str = un_pro_str.substr(_city1 + 1); |
||||
|
} else if (_region != -1) { //区
|
||||
|
area.city = un_pro_str.substring(0, _region + 1) |
||||
|
un_city_str = un_pro_str.substr(_region + 1); |
||||
|
} else if (_county != -1) { //县
|
||||
|
area.city = un_pro_str.substring(0, _county + 1) |
||||
|
un_city_str = un_pro_str.substr(_county + 1); |
||||
|
} |
||||
|
|
||||
|
var reg = /.+?(市|县|区)/g; |
||||
|
var aaa; |
||||
|
aaa = un_city_str.match(reg); |
||||
|
area.country = aaa[0]; |
||||
|
var xiangxi = str.substring(str.indexOf(aaa[0]) + 3) |
||||
|
area.address = xiangxi |
||||
|
|
||||
|
return area; |
||||
|
} |
||||
Loading…
Reference in new issue