关于判断邮箱 手机号等一系列的正则表达式

//邮箱

+ (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-02 21:03:42

关于判断邮箱 手机号等一系列的正则表达式的相关文章

关于判断邮箱 手机号等一系列的正则表达式。。。。。

//邮箱 + (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

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.

判断手机号,密码的正则表达式

//判断密码6-16位 + (BOOL)validatePassword:(NSString *)password{ NSString *Regex = @"^[a-zA-Z0-9]{5,16}$"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex]; return [emailTest evaluateWithObject:password];

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

ORACLE中使用SQL的正则表达式判断邮箱格式

在数据库中,有时需要判断字符串是否是一个或者多个邮箱格式,可以使用如下语句判断: SELECT COUNT(1) FROM dual WHERE regexp_like(v_mail,'^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+(;{1,1}\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+)*$') 代码中v_

php filter_var函数判断邮箱,url,ip格式

以前使用php的时候还不知道有过滤器filter这玩意,那时候判断邮箱.url和ip地址格式是否符合都是用正则表达式.后来随着使用的逐渐深入,才知道在php中也可以使用内置的函数库过滤器filter来完成这些功能.对于filter_var这个函数,如果验证通过则会返回验证对象,否则返回false.判断邮箱<?php$email = '[email protected]'; $result = filter_var($email, FILTER_VALIDATE_EMAIL); 判断url<?p

判断 邮箱格式是否正确

练习:判断邮箱格式是否正确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)

判断邮箱格式和图片压缩

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