#import "ViewController.h"
@interface ViewController ()
{
UITextField *textF;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
textF = [[UITextField alloc] initWithFrame:CGRectMake(100, 200, 200, 30)];
textF.placeholder = @"请输入三个正数相乘";
textF.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:textF];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(150, 250, 100, 25)];
[btn setTitle:@"验证" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
- (void)btnAction {
[[UIApplication sharedApplication].keyWindow endEditing:YES];
NSLog(@"%@", [self isThreeNumberMultiply:textF.text] ? @"恭喜你!" : @"输错啦!");
}
-(BOOL)isThreeNumberMultiply:(NSString *)str {
NSString *regex = @"[\\d.]*[*][\\d.]*[*][\\d.]*";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
return [predicate evaluateWithObject:str];
}
@end
iOS 正则表达式判断3个正数相乘
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 判断手机所属运营商 判断手机号是否正确 判断用户身份证号码15位或者18位 判断用户姓名,20位的中文或英文 检测...
- 主观能动性 在大学要必须发挥得淋漓尽致 大学四年就是得靠自学,不管是专业还是非专业你感兴趣的,跟着老师上下课盲目应...