一,正则表达式:
^(0|[1-9]\d{0,6})([.]?\d{1,2})?$
^,$ :开始和结尾;
|:或者;
[1-9] : 允许输入1到9 的数据;
{0,6} :允许输入0到6位;
[.]? : 如果有小数点;
{1,2} :小数部分,1到2位;
二,正则表达式判断是不是手机号:
/**
*手机号码
*移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
*联通:130,131,132,152,155,156,185,186
*电信:133,1349,153,180,189,181(增加)
*/
- (BOOL) isMobile:(NSString *)mobileNumbel{
NSString * MOBIL = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
//中国移动:China Mobile
NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[2378])\\d)\\d{7}$";
//中国联通:China Unicom
NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
//中国电信:China Telecom
NSString * CT = @"^1((33|53|8[019])[0-9]|349)\\d{7}$";
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBIL];
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
BOOL isMobile = NO;
if (([regextestmobile evaluateWithObject:mobileNumbel]
|| [regextestcm evaluateWithObject:mobileNumbel]
|| [regextestct evaluateWithObject:mobileNumbel]
|| [regextestcu evaluateWithObject:mobileNumbel])) {
isMobile = YES;
}
return isMobile;
}
褚小者不可以怀大,绠短者不可以汲深。
网友评论