Commit a71e4df4429d4931bf206a0e53ad25cb37de0b38
1 parent
637ab2bd
我的地址 , 验证手机号
Showing
4 changed files
with
34 additions
and
3 deletions
pages/user/add_address/add_address.js
| @@ -50,9 +50,18 @@ Page({ | @@ -50,9 +50,18 @@ Page({ | ||
| 50 | var a= this.data.address, b=a,th=this; | 50 | var a= this.data.address, b=a,th=this; |
| 51 | Object.assign(a, s.detail.value), a.is_default = Number(a.is_default); | 51 | Object.assign(a, s.detail.value), a.is_default = Number(a.is_default); |
| 52 | a.store_id = os.stoid; | 52 | a.store_id = os.stoid; |
| 53 | + | ||
| 54 | + var ob = ut.check_mobile(a.mobile); | ||
| 55 | + if(ob.code!=1){ | ||
| 56 | + return getApp().my_warnning(ob.title,0,th); | ||
| 57 | + } | ||
| 58 | + | ||
| 53 | if (a.more_address == null || a.more_address == undefined || a.more_address=="" ){ | 59 | if (a.more_address == null || a.more_address == undefined || a.more_address=="" ){ |
| 54 | - wx.showModal({title: "请选择地区"}); return false; | 60 | + getApp().my_warnning("请选择地区",0,th); |
| 61 | + return false; | ||
| 55 | } | 62 | } |
| 63 | + | ||
| 64 | + | ||
| 56 | //判断是不是空对象 | 65 | //判断是不是空对象 |
| 57 | //--------如果是修改地址---------- | 66 | //--------如果是修改地址---------- |
| 58 | if (!th.data.isnew){ | 67 | if (!th.data.isnew){ |
pages/user/add_address/add_address.json
pages/user/add_address/add_address.wxml
| @@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
| 7 | </view> | 7 | </view> |
| 8 | <view class="item"> | 8 | <view class="item"> |
| 9 | <view class="item-name">手机号码:</view> | 9 | <view class="item-name">手机号码:</view> |
| 10 | - <input class="item-input" name="mobile" value="{{address.mobile}}"></input> | 10 | + <input type="number" class="item-input" name="mobile" value="{{address.mobile}}"></input> |
| 11 | </view> | 11 | </view> |
| 12 | <view bindtap="openRegionsModal" class="item" data-id="0"> | 12 | <view bindtap="openRegionsModal" class="item" data-id="0"> |
| 13 | <view class="item-name">所在地区:</view> | 13 | <view class="item-name">所在地区:</view> |
| @@ -31,3 +31,5 @@ | @@ -31,3 +31,5 @@ | ||
| 31 | </form> | 31 | </form> |
| 32 | </view> | 32 | </view> |
| 33 | <template is="regions" data="{{regions:regions}}"></template> | 33 | <template is="regions" data="{{regions:regions}}"></template> |
| 34 | + | ||
| 35 | +<warn id="warn"></warn> |
utils/util.js
| @@ -230,6 +230,22 @@ function measureText(text, fontSize = 10) { | @@ -230,6 +230,22 @@ function measureText(text, fontSize = 10) { | ||
| 230 | return width * fontSize / 10; | 230 | return width * fontSize / 10; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | +//验证手机号 | ||
| 234 | +function check_mobile(phoneMobile){ | ||
| 235 | + var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/; | ||
| 236 | + var ob={code:1}; | ||
| 237 | + if (phoneMobile.length === 0) { | ||
| 238 | + ob.title='输入的手机号为空'; | ||
| 239 | + ob.code=-1; | ||
| 240 | + } else if (phoneMobile.length < 11) { | ||
| 241 | + ob.title ='手机号长度有误!'; | ||
| 242 | + ob.code = -1; | ||
| 243 | + } else if (!myreg.test(phoneMobile)) { | ||
| 244 | + ob.title = '手机号格式有误!'; | ||
| 245 | + ob.code = -1; | ||
| 246 | + } | ||
| 247 | + return ob; | ||
| 248 | +} | ||
| 233 | 249 | ||
| 234 | module.exports = { | 250 | module.exports = { |
| 235 | formatTime: function(e, r) { | 251 | formatTime: function(e, r) { |
| @@ -319,4 +335,5 @@ module.exports = { | @@ -319,4 +335,5 @@ module.exports = { | ||
| 319 | isArray: isArray, | 335 | isArray: isArray, |
| 320 | sub_last: sub_last,//去掉末尾一个字符 | 336 | sub_last: sub_last,//去掉末尾一个字符 |
| 321 | measureText: measureText,//画布需要的函数 | 337 | measureText: measureText,//画布需要的函数 |
| 338 | + check_mobile: check_mobile,//验证手机 | ||
| 322 | }; | 339 | }; |