#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@end
@implementation ViewController
- (IBAction)BUTMessage:(id)sender {
NSString *phone = self.phoneTF.text;
NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0-9])|(14[57])|(17[013678]))\\d{8}$";
NSPredicate *preURL = [NSPredicate predicateWithFormat:@"self matches%@",phoneRegex];
BOOL b1 = [preURL evaluateWithObject:phone];
if (b1) {
NSLog(@"正确");
}else{
NSLog(@"不正确");
}
- (IBAction)SFZBUT:(id)sender {
NSString *phone = self.phoneTF.text;
NSString *SfZRegex = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
NSPredicate *preURL = [NSPredicate predicateWithFormat:@"self matches%@",SfZRegex];
BOOL b1 = [preURL evaluateWithObject:phone];
if (b1) {
NSLog(@"正确");
}else{
NSLog(@"不正确");
}
}
- (IBAction)YXBUT:(id)sender {
NSString *phone = self.phoneTF.text;
NSString *YXRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *preURL = [NSPredicate predicateWithFormat:@"self matches%@",YXRegex];
BOOL b1 = [preURL evaluateWithObject:phone];
if (b1) {
NSLog(@"正确");
}else{
NSLog(@"不正确");
}
}
- (IBAction)YM:(id)sender {
NSString *phone = self.phoneTF.text;
NSString *YHMRegex = @"^[A-Za-z0-9]{6,20}+$";
NSPredicate *preURL = [NSPredicate predicateWithFormat:@"self matches%@",YHMRegex];
BOOL b1 = [preURL evaluateWithObject:phone];
if (b1) {
NSLog(@"正确");
}else{
NSLog(@"不正确");
}
}