iOS - 正则表达式判断邮箱、身份证..是否正确

 

   

+ (BOOL) validateEmail:(NSString *)email

{

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

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

    return [emailTest evaluateWithObject:email];

}

 

 

//手机号码验证

+ (BOOL) validateMobile:(NSString *)mobile

{

    //手机号以13, 15,18开头,八个 \d 数字字符

    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";

    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];

    return [phoneTest evaluateWithObject:mobile];

}

 

 

//车牌号验证

+ (BOOL) validateCarNo:(NSString *)carNo

{

    NSString *carRegex = @"^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$";

    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];

    NSLog(@"carTest is %@",carTest);

    return [carTest evaluateWithObject:carNo];

}

 

 

//车型

+ (BOOL) validateCarType:(NSString *)CarType

{

    NSString *CarTypeRegex = @"^[\u4E00-\u9FFF]+$";

    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CarTypeRegex];

    return [carTest evaluateWithObject:CarType];

}

 

 

//用户名

+ (BOOL) validateUserName:(NSString *)name

{

    NSString *userNameRegex = @"^[A-Za-z0-9]{6,20}+$";

    NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];

    BOOL B = [userNamePredicate evaluateWithObject:name];

    return B;

}

 

 

//密码

+ (BOOL) validatePassword:(NSString *)passWord

{

    NSString *passWordRegex = @"^[a-zA-Z0-9]{6,20}+$";

    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];

    return [passWordPredicate evaluateWithObject:passWord];

}

 

 

//昵称

+ (BOOL) validateNickname:(NSString *)nickname

{

    NSString *nicknameRegex = @"^[\u4e00-\u9fa5]{4,8}$";

    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",nicknameRegex];

    return [passWordPredicate evaluateWithObject:nickname];

}

 

 

//身份证号

+ (BOOL) validateIdentityCard: (NSString *)identityCard

{

    BOOL flag;

    if (identityCard.length <= 0) {

        flag = NO;

        return flag;

    }

    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";

    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];

    return [identityCardPredicate evaluateWithObject:identityCard];

}

时间: 2024-11-08 19:58:02

iOS - 正则表达式判断邮箱、身份证..是否正确的相关文章

iOS - 正则表达式判断邮箱、身份证..是否正确:

//邮箱 + (BOOL) validateEmail:(NSString *)email { NSString *emailRegex = @"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; retur

几个ios正则表达式 判断邮箱 手机号码 身份证号码

[objc] view plaincopy //判断是否为邮箱 - (BOOL) validateEmail: (NSString *) candidate { NSString *emailRegex = @"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MAT

iOS 正则表达式-判断邮箱、手机号

判断是否是邮箱 -(BOOL)isValidateEmail:(NSString *)email { NSString *emailRegex = @"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailRegex]; retu

python 正则表达式判断邮箱格式是否正确

import re def validateEmail(email): if len(email) > 7: if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None: return 1 return 0

Java编程:正则表达式判断邮箱及电话号码是否有效

/** * 正则判断邮箱及电话号码是否有效 * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入你的邮箱:");  String email = sc.next();   System.out.println("请输入你的电话号码:");      String phone = sc.

iOS之判断手机号码格式是否正确

//判断手机号码格式是否正确 + (BOOL)valiMobile:(NSString *)mobile{     mobile = [mobile stringByReplacingOccurrencesOfString:@" " withString:@""];     if (mobile.length != 11)     {         return NO;     }else{         /**          * 移动号段正则表达式    

Js使用正则表达式判断邮箱格式

1 <html> 2 <head> 3 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 4 <title>验证Email是否正确</title> 5 <script language="javascript"> 6 function checkemail(str){ 7 //在Jav

判断 邮箱格式是否正确

练习:判断邮箱格式是否正确1.有且只能有一个@2.不能以@开头[email protected]之后至少有一个.[email protected]和.不能靠在一起5.不能以.结尾 1 Console.Write("请输入邮箱地址:"); 2 string m = Console.ReadLine(); 3 if (m.IndexOf("@") == m.LastIndexOf("@")) 4 { 5 if (m.IndexOf("@&q

判断邮箱 格式是否正确

/练习:判断邮箱格式是否正确 //1.有且只能有一个@ contains @ indexof @=lastindexof //2.不能以@开头 indexof != 0 //[email protected]之后至少有一个. //[email protected]和.不能靠在一起 //5.不能以.结尾 Console.Write("请输入您的邮箱:"); string s = Console.ReadLine(); if(s.Contains("@")==true)