实例如下:
//判断手机号码格式是否正确 + (bool)valimobile:(nsstring *)mobile { mobile = [mobile stringbyreplacingoccurrencesofstring:@" " withstring:@""]; if (mobile.length != 11) { return no; }else{ /** * 移动号段正则表达式 */ nsstring *cm_num = @"^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$"; /** * 联通号段正则表达式 */ nsstring *cu_num = @"^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$"; /** * 电信号段正则表达式 */ nsstring *ct_num = @"^((133)|(153)|(177)|(18[0,1,9]))\\d{8}$"; nspredicate *pred1 = [nspredicate predicatewithformat:@"self matches %@", cm_num]; bool ismatch1 = [pred1 evaluatewithobject:mobile]; nspredicate *pred2 = [nspredicate predicatewithformat:@"self matches %@", cu_num]; bool ismatch2 = [pred2 evaluatewithobject:mobile]; nspredicate *pred3 = [nspredicate predicatewithformat:@"self matches %@", ct_num]; bool ismatch3 = [pred3 evaluatewithobject:mobile]; if (ismatch1 || ismatch2 || ismatch3) { return yes; }else{ return no; } } }
以上这篇ios利用正则表达式判断手机号码格式是否正确的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
M - Jamie‘s Contact Groups POJ - 2289(二分 + 多重匹配)
H - Antenna Placement POJ - 3020(最小边覆盖)
Unity组件【Camera && Flare Layer】
K - Treasure Exploration POJ - 2594
网友评论