//验证邮箱格式是否正确
-(BOOL)validateEmail:(NSString*)candidate
{
NSString*emailRegex=
[A-Z0-9a-z._%+-]+[A-Za-z0-9.-]+\\.[A-Za-z]{2,4};NSPredicate*emailTest=[NSPredicatepredicateWithFormat:
SELFMATCHES%,emailRegex];return[emailTestevaluateWithObject:candidate];
}
//验证车牌号格式
-(BOOL)validateCarNo:(NSString*)carNo{
NSString*carRegex=
^[A-Za-z]{1}[A-Za-z_0-9]{5};NSPredicate*carTest=[NSPredicatepredicateWithFormat:
SELFMATCHES%,carRegex];NSLog(
carTestis%,carTest);return[carTestevaluateWithObject:carNo];
}
//验证手机号码格式
-(BOOL)isMobileNumber:(NSString*)mobileNum
{
NSString*MOBILE=
^1(3[0-9]5[0-35-9]
8[-9])\\d{8};
NSString*CM=
^1(34[0-8](3[5-9]
5[-9]
8[])\\d)\\d{7};
NSString*CU=
^1(3[0-2]5[]
8[56])\\d{8};
NSString*CT=
^1((3353
8[09])[0-9]
)\\d{7};
//NSString*PHS=
^0(102[0-]
\\d{3})\\d{7,8};
NSPredicate*regextestmobile=[NSPredicatepredicateWithFormat:
SELFMATCHES%,MOBILE];NSPredicate*regextestcm=[NSPredicatepredicateWithFormat:
SELFMATCHES%,CM];NSPredicate*regextestcu=[NSPredicatepredicateWithFormat:
SELFMATCHES%,CU];NSPredicate*regextestct=[NSPredicatepredicateWithFormat:
SELFMATCHES%,CT];if(([regextestmobileevaluateWithObject:mobileNum]==YES)
([regextestcmevaluateWithObject:mobileNum]==YES)
([regextestctevaluateWithObject:mobileNum]==YES)
([regextestcuevaluateWithObject:mobileNum]==YES))
{
returnYES;
}
else
{
returnNO;
}
}
预览时标签不可点收录于话题#个上一篇下一篇