自用部分正则表达式

前端之家收集整理的这篇文章主要介绍了自用部分正则表达式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

是否为中文

-(BOOL)isChinese{

NSString *match=@"(^[\u4e00-\u9fa5]+$)";

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF matches %@",match];

return [predicate evaluateWithObject:self];

}

- (BOOL)isValidateEmail:(NSString *)Email

{

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

NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailCheck];

return [emailTest evaluateWithObject:Email];

}

- (BOOL) isEmail{

NSString *emailRegEx =

@"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"

@"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"

@"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"

@"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"

@"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"

@"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"

@"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";

NSPredicate *regExPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",emailRegEx];

return [regExPredicate evaluateWithObject:[self lowercaseString]];

}

猜你在找的正则表达式相关文章