IOS正则表达式---by talent.L

常用正则表示


1.QQ号

//数字组成 10000开始

NSString * str =@"[1-9][0-9]{4,}";

2.网址

NSString * str =@"((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)";


3身份证

NSString *str = @"/(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)/";

4手机号

NSString *str1 = @"^((13[0-9])|(15[^4,\\D])|(18[0-9])|(14[57])|(17[013678]))\\d{8}$";

5电子邮箱

NSString *str1 = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";


if (self.yhjtext.text.length >0) {

//16或19位银行卡号

NSString * str =@"^([0-9]{16}|[0-9]{19})$";

//谓词

NSPredicate * pre =[NSPredicate predicateWithFormat:@"self matches %@",str];

BOOL is =[pre evaluateWithObject: self.yhjtext.text];

if (is) {

UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"银行卡号标明" message:@"正确" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction * ac1 =[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

UIAlertAction * ac2 =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

}];

[alert addAction:ac1];

[alert addAction:ac2];

[self presentViewController:alert animated:NO completion:^{

}];

}

else{

UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"银行卡号码标明" message:@"不正确" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction * ac1 =[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

UIAlertAction * ac2 =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

}];

[alert addAction:ac1];

[alert addAction:ac2];

[self presentViewController:alert animated:NO completion:^{

}];

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容