大家好,又见面了,我是你们的朋友全栈君。
//进行邮箱正则表达式判断
-(BOOL) validateEmail
{
NSString *emailRegex = @”[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}”;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@”SELF MATCHES %@”, emailRegex];
return [emailTest evaluateWithObject:self];
}
这里面的self 是因为这个方法是写在category的 NSString + SiZheString.m 中
所以调取方式应该是
if([@”字符串” validateEmail]){
}
这种样式
如果是自己不想封装
NSString *emailRegex = @”[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}”;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@”SELF MATCHES %@”, emailRegex];
Bool isTrue = [emailTest evaluateWithObject:@”字符串”];
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/149472.html原文链接:https://javaforall.cn