前言: 检测密码 邮箱 IP地址 手机号输入是否正确 已经封装好了,拖入工程就可以使用!
//邮箱正则表达式
+ (BOOL)validateEmail:(NSString*)email
{
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:email];
}
密码正则表达式
//密码正则
+ (BOOL)validatePassword:(NSString*)passWord
{
NSString*passWordRegex =@"^[a-zA-Z0-9]{6,20}+$";
NSPredicate*passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
return[passWordPredicate evaluateWithObject:passWord];
}
IP地址正则表达式
([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}
手机号正则(包含了170 177 号码段)
- (BOOL)checkTel:(NSString*)mobileNumbel
{
/**
*手机号码
*移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
*联通:130,131,132,152,155,156,185,186,183
*电信:133,1349,153,180,189,177
*其他170
*/
NSString* MOBILE =@"^1(3[0-9]|5[0-35-9]|8[025-9]|7[07])\\d{8}$";
NSString* CM =@"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
NSString* CU =@"^1(3[0-2]|5[256]|8[356])\\d{8}$";
NSString* CT =@"^1((33|53|8[09])[0-9]|349|7[07])\\d{7}$";
// NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
NSPredicate*regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
NSPredicate*regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
NSPredicate*regextestcu = [NSPredicatepre dicateWithFormat:@"SELF MATCHES %@", CU];
NSPredicate*regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
if(([regextestmobile evaluateWithObject:mobileNumbel] ==YES)
|| ([regextestcm evaluateWithObject:mobileNumbel] ==YES)
|| ([regextestct evaluateWithObject:mobileNumbel] ==YES)
|| ([regextestcu evaluateWithObject:mobileNumbel] ==YES))
{
returnYES;
}
else
{
// 错误 输入框抖动
CAKeyframeAnimation*anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
anim.duration=0.2;
anim.repeatCount=2;
anim.values=@[@-20,@20, @-20];
[_proTokenView.textfield1.layeraddAnimation:animforKey:nil];
DXAlertView*alert = [[DXAlertViewalloc]initWithTitle:@"温馨提示"contentText:@"请输入正确的手机号码"leftButtonTitle:@"知道了"rightButtonTitle:@"取消"];
[alertshow];
returnNO;
}
}