現(xiàn)在的app更多的是采用手機號進行注冊登錄梦湘,所以對于手機號的對錯進行判斷就成了現(xiàn)在許多程序猿必須要做的功能,下面的就是對手機號判斷的方法:
NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[0678])\\d{8}$";
NSString *CM = @"(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\\d{8}$)|(^1705\\d{7}$)";
NSString *CU = @"(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\\d{8}$)|(^1709\\d{7}$)";
NSString *CT = @"(^1(33|53|77|8[019])\\d{8}$)|(^1700\\d{7}$)";
NSPredicate *regextestmobile1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
NSPredicate *regextestcm1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
NSPredicate *regextestcu1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
NSPredicate *regextestct1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
if (self._textfiled.text.length !=11 ) {
UIAlertView * alert2 = [[UIAlertView alloc]initWithTitle:nil message:@"您還沒有輸入電話號" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alert2 show];
}
if (([regextestmobile1 evaluateWithObject:self._textfiled.text] == YES)
|| ([regextestcm1 evaluateWithObject:self._textfiled.text] == YES)
|| ([regextestct1 evaluateWithObject:self._textfiled.text] == YES)
|| ([regextestcu1 evaluateWithObject:self._textfiled.text] == YES)){
這里寫判斷手機號正確后的邏輯
}