正则匹配电话、QQ、邮箱

前端之家收集整理的这篇文章主要介绍了正则匹配电话、QQ、邮箱前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
/* 匹配电话号码 */
-(
BOOL )matchPhone:( NSString *)str
{
if ([str isEqualToString : @" 联系电话 " ]) {
return YES ;
}
else
{
// 座机
NSString *phoneRegex1 = @"\\d{3}-\\d{8}|\\d{4}-\\d{7,8}" ;
NSPredicate *phoneTest1 = [ NSPredicate predicateWithFormat : @"SELF MATCHES %@" ,phoneRegex1];
// 手机
NSString *phoneRegex2 = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9])|(17[0,5-9]))\\d{8}$" ;
NSPredicate *phoneTest2 = [ NSPredicate predicateWithFormat : @"SELF MATCHES %@" ,phoneRegex2];
return ([phoneTest1 evaluateWithObject :str]||[phoneTest2 evaluateWithObject :str]);

}
}

/* 匹配 QQ*/
-(
BOOL )matchQQ:( NSString *)str
{
if ([str isEqualToString : @"QQ " ]) {
return YES ;
}
else
{
NSString *emailRegex = @"[0-9]{5,12}" ;
NSPredicate *emailTest = [ NSPredicate predicateWithFormat : @"SELF MATCHES %@" ,emailRegex];
return [emailTest evaluateWithObject :str];
}

}

/* 匹配邮箱 */
-(
BOOL )matchMail:( NSString *)str
{
if ([str isEqualToString : @" 邮箱 " ]) {
return YES ;
}
else
{
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z].*" ;
NSPredicate *emailTest = [ NSPredicate predicateWithFormat : @"SELF MATCHES %@" ,emailRegex];
return [emailTest evaluateWithObject :str]; } } 原文链接:https://www.f2er.com/regex/361219.html

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