一、日常生活常用正则
1 Email地址:^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$2 域名:[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?3 InternetURL:[a-zA-z]+://[^\s]* 或 ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$4 手机号码:^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$5 电话号码("XXX-XXXXXXX"、"XXXX-XXXXXXXX"、"XXX-XXXXXXX"、"XXX-XXXXXXXX"、"XXXXXXX"和"XXXXXXXX):^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$6 国内电话号码(0511-4405222、021-87888822):\d{3}-\d{8}|\d{4}-\d{7}7 身份证号(15位、18位数字):^\d{15}|\d{18}$8 短身份证号码(数字、字母x结尾):^([0-9]){7,18}(x|X)?$ 或 ^\d{8,18}|[0-9x]{8,18}|[0-9X]{8,18}?$9 帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$10 密码(以字母开头,长度在6~18之间,只能包含字母、数字和下划线):^[a-zA-Z]\w{5,17}$11 强密码(必须包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间):^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$12 日期格式:^\d{4}-\d{1,2}-\d{1,2}13 一年的12个月(01~09和1~12):^(0?[1-9]|1[0-2])$14 一个月的31天(01~09和1~31):^((0?[1-9])|((1|2)[0-9])|30|31)$15 钱的输入格式:16 1.有四种钱的表示形式我们可以接受:"10000.00" 和 "10,000.00", 和没有 "分" 的 "10000" 和 "10,000":^[1-9][0-9]*$17 2.这表示任意一个不以0开头的数字,但是,这也意味着一个字符"0"不通过,所以我们采用下面的形式:^(0|[1-9][0-9]*)$18 3.一个0或者一个不以0开头的数字.我们还可以允许开头有一个负号:^(0|-?[1-9][0-9]*)$19 4.这表示一个0或者一个可能为负的开头不为0的数字.让用户以0开头好了.把负号的也去掉,因为钱总不能是负的吧.下面我们要加的是说明可能的小数部分:^[0-9]+(.[0-9]+)?$20 5.必须说明的是,小数点后面至少应该有1位数,所以"10."是不通过的,但是 "10" 和 "10.2" 是通过的:^[0-9]+(.[0-9]{2})?$21 6.这样我们规定小数点后面必须有两位,如果你认为太苛刻了,可以这样:^[0-9]+(.[0-9]{1,2})?$22 7.这样就允许用户只写一位小数.下面我们该考虑数字中的逗号了,我们可以这样:^[0-9]{1,3}(,[0-9]{3})*(.[0-9]{1,2})?$23 8.1到3个数字,后面跟着任意个 逗号+3个数字,逗号成为可选,而不是必须:^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$24 备注:这就是最终结果了,别忘了"+"可以用"*"替代如果你觉得空字符串也可以接受的话(奇怪,为什么?)最后,别忘了在用函数时去掉去掉那个反斜杠,一般的错误都在这里25 xml文件:^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$26 中文字符的正则表达式:[\u4e00-\u9fa5]27 双字节字符:[^\x00-\xff] (包括汉字在内,可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1))28 空白行的正则表达式:\n\s*\r (可以用来删除空白行)29 HTML标记的正则表达式:<(\S*?)[^>]*>.*?</\1>|<.*? /> (网上流传的版本太糟糕,上面这个也仅仅能部分,对于复杂的嵌套标记依旧无能为力)30 首尾空白字符的正则表达式:^\s*|\s*$或(^\s*)|(\s*$) (可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式)31 腾讯QQ号:[1-9][0-9]{4,} (腾讯QQ号从10000开始)32 中国邮政编码:[1-9]\d{5}(?!\d) (中国邮政编码为6位数字)33 IP地址:\d+\.\d+\.\d+\.\d+ (提取IP地址时有用)34 IP地址:((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))
二、字符匹配
1 汉字:^[\u4e00-\u9fa5]{0,}$2 英文和数字:^[A-Za-z0-9]+$ 或 ^[A-Za-z0-9]{4,40}$3 长度为3-20的所有字符:^.{3,20}$4 由26个英文字母组成的字符串:^[A-Za-z]+$5 由26个大写英文字母组成的字符串:^[A-Z]+$6 由26个小写英文字母组成的字符串:^[a-z]+$7 由数字和26个英文字母组成的字符串:^[A-Za-z0-9]+$8 由数字、26个英文字母或者下划线组成的字符串:^\w+$ 或 ^\w{3,20}$9 中文、英文、数字包括下划线:^[\u4E00-\u9FA5A-Za-z0-9_]+$10 中文、英文、数字但不包括下划线等符号:^[\u4E00-\u9FA5A-Za-z0-9]+$ 或 ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$11 可以输入含有^%&',;=?$\"等字符:[^%&',;=?$\x22]+12 禁止输入含有~的字符:[^~\x22]+
三、数字匹配
1 数字:^[0-9]*$2 n位的数字:^\d{n}$3 至少n位的数字:^\d{n,}$4 m-n位的数字:^\d{m,n}$5 零和非零开头的数字:^(0|[1-9][0-9]*)$6 非零开头的最多带两位小数的数字:^([1-9][0-9]*)+(.[0-9]{1,2})?$7 带1-2位小数的正数或负数:^(\-)?\d+(\.\d{1,2})?$8 正数、负数、和小数:^(\-|\+)?\d+(\.\d+)?$9 有两位小数的正实数:^[0-9]+(.[0-9]{2})?$10 有1~3位小数的正实数:^[0-9]+(.[0-9]{1,3})?$11 非零的正整数:^[1-9]\d*$ 或 ^([1-9][0-9]*){1,3}$ 或 ^\+?[1-9][0-9]*$12 非零的负整数:^\-[1-9][]0-9"*$ 或 ^-[1-9]\d*$13 非负整数:^\d+$ 或 ^[1-9]\d*|0$14 非正整数:^-[1-9]\d*|0$ 或 ^((-\d+)|(0+))$15 非负浮点数:^\d+(\.\d+)?$ 或 ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$16 非正浮点数:^((-\d+(\.\d+)?)|(0+(\.0+)?))$ 或 ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$17 正浮点数:^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ 或 ^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$18 负浮点数:^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ 或 ^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$19 浮点数:^(-?\d+)(\.\d+)?$ 或 ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$
四、oc正则匹配类(项目常用)typedef enum{
CheckDataType_None,
CheckDataType_Empty,
CheckDataType_FormatWrong,
CheckDataType_Space
}CheckDataType;
@interface CheckDataValid : NSObject
+ (CheckDataType)checkPhoneData:(NSString *)phoneNum;//验证手机号
+ (CheckDataType)checkVcodeData:(NSString *)Vcode;//验证短信验证码格式
+ (CheckDataType)checkCallData:(NSString *)callStr;//用户昵称
+ (CheckDataType)checkWorkPhoneData:(NSString *)workPhoneStr;
+ (CheckDataType)checkWorkTimeData:(NSString *)workTimeStr;
+ (CheckDataType)checkMoreIntroData:(NSString *)moreIntroStr;
+ (CheckDataType)checkIdentityNumData:(NSString *)identityNum;
+ (CheckDataType)checkPasswordNumData:(NSString *)passwordNum;
+ (CheckDataType)checkOtherPapersNumData:(NSString *)otherPapersNum;
+ (CheckDataType)checkIncomeRateData:(NSString *)incomeRateStr;
+ (NSString *)getHidePhoneNum:(NSString *)phoneNum;
+ (NSString *)getHideIdentityNum:(NSString *)identityNum;
+ (BOOL)validateWorkPhoneNumber:(NSString*)number;
+ (BOOL)validateIdentityNumber:(NSString*)number;
+ (BOOL)validatePasswordNumber:(NSString*)number;
+ (BOOL)validateOtherPapersNumber:(NSString*)number;
//验证证件号
+ (BOOL)validateIdCard:(NSString*)idCard;//验证身份证号
+ (BOOL)validatePassportCard:(NSString*)passportNum;//验证护照号
+ (BOOL)validateGangAoPassportNumber:(NSString*)GangAoPassportNumber;//验证港澳通行证
+ (BOOL)validate*PassportNumber:(NSString*)*PassportNumber;//验证台胞证
+ (BOOL)validateLegalOfficerNumber:(NSString*)OfficerNumber;//验证军官证
+ (BOOL)validateLegalUAAPNumber:(NSString*)UAAPNumber;//验证uuap号
/**
* 验证纳税人识别码/统一社会信用代码
* 号码格式:
* ①验证纳税人识别码:6位行政区划码(纯数字)+ 9位组织机构代码(数字或大写字母)
* ②统一社会信用代码(18位):第1位(登记管理部门代码,数字或字母)、第2位(机构类别代码,数字或字母)
* 第3—8位(登记管理机关行政区划码,数字)、第9—17位(主体标识码,数字或字母)
* 第18位(校验码,数字或字母)
*/
+ (BOOL)validateTaxpayerNumber:(NSString*)TaxpayerNumber;//验证纳税人识别码
@end
@implementation CheckDataValid
+ (CheckDataType)checkPhoneData:(NSString *)phoneNum{
if ([phoneNum isEqualToString:@""]) {
return CheckDataType_Empty;
}
else if([phoneNum length] != 11){
return CheckDataType_FormatWrong;
}
NSString *regex = @"^((13[0-9])|(17[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$";
// NSString *regex = @"^((13[0-9])|(15[^4,\\D])|(18[0-9])|(17[0-9]))|\\d{8}$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if(![pred evaluateWithObject: phoneNum]){
return CheckDataType_FormatWrong;
}
return CheckDataType_None;
}
+ (CheckDataType)checkVcodeData:(NSString *)Vcode{
if ([Vcode isEqualToString:@""]) {
return CheckDataType_Empty;
}
else if([Vcode length] != 6){
return CheckDataType_FormatWrong;
}
NSRange _range = [Vcode rangeOfString:@" "];
if (_range.location != NSNotFound) {
return CheckDataType_Space;
}
return CheckDataType_None;
}
+ (CheckDataType)checkCallData:(NSString *)callStr{
if ([callStr isEqualToString:@""]) {
return CheckDataType_Empty;
}
NSRange _range = [callStr rangeOfString:@" "];
if (_range.location != NSNotFound) {
return CheckDataType_Space;
}
if(([callStr length] <2) || ([callStr length] >16)){
return CheckDataType_FormatWrong;
}
NSString *regex = @"[a-zA-Z0-9\u4e00-\u9fa5]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if(![pred evaluateWithObject: callStr]){
return CheckDataType_FormatWrong;
}
return CheckDataType_None;
}
+ (CheckDataType)checkCompanyNameData:(NSString *)companyName{
if ([companyName isEqualToString:@""]) {
return CheckDataType_Empty;
}
NSRange _range = [companyName rangeOfString:@" "];
if (_range.location != NSNotFound) {
return CheckDataType_Space;
}
if(([companyName length] <2) || ([companyName length] >20)){
return CheckDataType_FormatWrong;
}
NSString *regex = @"[a-zA-Z.\u4e00-\u9fa5]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if(![pred evaluateWithObject: companyName]){
return CheckDataType_FormatWrong;
}
return CheckDataType_None;
}
+ (CheckDataType)checkOrganizationNameData:(NSString *)companyName{
if ([companyName isEqualToString:@""]) {
return CheckDataType_Empty;
}
NSRange _range = [companyName rangeOfString:@" "];
if (_range.location != NSNotFound) {
return CheckDataType_Space;
}
if(([companyName length] <2) || ([companyName length] >16)){
return CheckDataType_FormatWrong;
}
NSString *regex = @"[\u4e00-\u9fa5]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if(![pred evaluateWithObject: companyName]){
return CheckDataType_FormatWrong;
}
return CheckDataType_None;
}
+ (CheckDataType)checkAddressData:(NSString *)addressStr{
if ([addressStr isEqualToString:@""]) {
return CheckDataType_Empty;
}
NSRange _range = [addressStr rangeOfString:@" "];
if (_range.location != NSNotFound) {
return CheckDataType_Space;
}
if(([addressStr length] <2) || ([addressStr length] >36)){
return CheckDataType_FormatWrong;
}
NSString *regex = @"[a-zA-Z0-9\u4e00-\u9fa5]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if(![pred evaluateWithObject: addressStr]){
return CheckDataType_FormatWrong;
}
return CheckDataType_None;
}
+ (CheckDataType)checkWorkPhoneData:(NSString *)workPhoneStr{
if ([workPhoneStr isEqualToString:@""]) {
return CheckDataType_Empty;
}
NSRange _range = [workPhoneStr rangeOfString:@" "];
if (_range.location != NSNotFound) {
return CheckDataType_Space;
}
if([workPhoneStr length] > 20){
return CheckDataType_FormatWrong;
}
// NSString *regex = @"[0-9-]+";
// NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
//
// if(![pred evaluateWithObject: workPhoneStr]){
// return CheckDataType_FormatWrong;
// }
//
// NSRange rangeH = [workPhoneStr rangeOfString:@"-"];
// if (rangeH.location != NSNotFound) {
// NSRange rangeS = [workPhoneStr rangeOfString:@"-"];
// if ((rangeS.location != 3)&&(rangeS.location != 4)) {
// return CheckDataType_FormatWrong;
// }
// }
// else{
// return CheckDataType_FormatWrong;
// }
// NSString *regex = @"(\d{4}-|\d{3}-)?(\d{8}|\d{7})";
// NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
//
// if(![pred evaluateWithObject: workPhoneStr]){
// return CheckDataType_FormatWrong;
// }
return CheckDataType_None;
}
//注明:工作时间不加限制条件,只限制字符数量
+ (CheckDataType)checkWorkTimeData:(NSString *)workTimeStr{
if ([workTimeStr isEqualToString:@""]) {
return CheckDataType_Empty;
}
NSRange _range = [workTimeStr rangeOfString:@" "];
if (_range.location != NSNotFound) {
return CheckDataType_Space;
}
if([workTimeStr length] >20){
return CheckDataType_FormatWrong;
}
// NSString *regex = @"[0-9-:\u4e00-\u9fa5]+";
// NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
//
// if(![pred evaluateWithObject: workTimeStr]){
// return CheckDataType_FormatWrong;
// }
return CheckDataType_None;
}
+ (CheckDataType)checkMoreIntroData:(NSString *)moreIntroStr{
if ([moreIntroStr isEqualToString:@""]) {
return CheckDataType_Empty;
}
// NSRange _range = [moreIntroStr rangeOfString:@" "];
// if (_range.location != NSNotFound) {
// return CheckDataType_Space;
// }
if([moreIntroStr length] >140){
return CheckDataType_FormatWrong;
}
// NSString *regex = @"[a-zA-Z0-9\u4e00-\u9fa5- :]+";
// NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
//
// if(![pred evaluateWithObject: moreIntroStr])
// {
// return CheckDataType_FormatWrong;
// }
return CheckDataType_None;
}
+ (CheckDataType)checkIdentityNumData:(NSString *)identityNum{
if ([identityNum isEqualToString:@""]) {
return CheckDataType_Empty;
}
NSRange _range = [identityNum rangeOfString:@" "];
if (_range.location != NSNotFound) {
return CheckDataType_Space;
}
// NSInteger l = [identityNum length];
if([identityNum length] == 18){
return CheckDataType_None;
}
return CheckDataType_FormatWrong;
}
+ (CheckDataType)checkOtherPapersNumData:(NSString *)passwordNum{
if ([passwordNum isEqualToString:@""]) {
return CheckDataType_Empty;
}
NSRange _range = [passwordNum rangeOfString:@" "];
if (_range.location != NSNotFound) {
return CheckDataType_Space;
}
NSString *firstStr = [passwordNum substringToIndex:1];
if (([firstStr isEqualToString:@"W"])||([firstStr isEqualToString:@"w"])) {
NSString *nextStr = [passwordNum substringFromIndex:1];
if (nextStr.length == 8) {
NSString *regex = @"[0-9]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if(![pred evaluateWithObject: nextStr])
{
return CheckDataType_FormatWrong;
}
return CheckDataType_None;
}
else{
return CheckDataType_FormatWrong;
}
}
else{
return CheckDataType_FormatWrong;
}
return CheckDataType_FormatWrong;
}
+ (CheckDataType)checkPasswordNumData:(NSString *)otherPapersNum{
if ([otherPapersNum isEqualToString:@""]) {
return CheckDataType_Empty;
}
NSRange _range = [otherPapersNum rangeOfString:@" "];
if (_range.location != NSNotFound) {
return CheckDataType_Space;
}
// NSString *firstStr = [otherPapersNum substringToIndex:1];
// if (([firstStr isEqualToString:@"G"])||([firstStr isEqualToString:@"g"])||([firstStr isEqualToString:@"E"])||([firstStr isEqualToString:@"e"])) {
NSString *nextStr = [otherPapersNum substringFromIndex:1];
if (nextStr.length == 5) {
NSString *regex = @"[0-9]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if(![pred evaluateWithObject: nextStr])
{
return CheckDataType_FormatWrong;
}
return CheckDataType_None;
}
else{
return CheckDataType_FormatWrong;
}
// }
// else{
// return CheckDataType_FormatWrong;
// }
return CheckDataType_FormatWrong;
}
+ (CheckDataType)checkIncomeRateData:(NSString *)incomeRateStr{
if ([incomeRateStr isEqualToString:@""]) {
return CheckDataType_Empty;
}
NSString *regex = @"[0-9.]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if(![pred evaluateWithObject: incomeRateStr])
{
return CheckDataType_FormatWrong;
}
NSArray *arry=[incomeRateStr componentsSeparatedByString:@"."];
if ([arry count] >2) {
return CheckDataType_FormatWrong;
}
NSString *pointStr;
if ([arry count] > 1) {
pointStr = [arry objectAtIndex:1];
if (pointStr.length > 2) {
return CheckDataType_FormatWrong;
}
}
return CheckDataType_None;
}
+ (NSString *)getHidePhoneNum:(NSString *)phoneNum{
NSString *newPhoneNum = @"";
if ([phoneNum isEqualToString:@""]) {
return newPhoneNum;
}
newPhoneNum = [phoneNum substringToIndex:3];
NSString *lastNum = [phoneNum substringFromIndex:7];
newPhoneNum = [NSString stringWithFormat:@"%@****%@",newPhoneNum,lastNum];
return newPhoneNum;
}
+ (NSString *)getHideIdentityNum:(NSString *)identityNum{
NSString *newIdentityNum = @"";
if (identityNum != nil) {
if(([identityNum length] == 15) || ([identityNum length] == 18)){
newIdentityNum = [identityNum substringToIndex:3];
NSInteger lastIndex = 0;
NSString *starStr = @"";
if (identityNum.length == 15) {
lastIndex = 11;
starStr = @"********";
}
else if(identityNum.length == 18){
lastIndex = 14;
starStr = @"***********";
}
NSString *lastNum = [identityNum substringFromIndex:lastIndex];
newIdentityNum = [NSString stringWithFormat:@"%@%@%@",newIdentityNum,starStr,lastNum];
}
}
return newIdentityNum;
}
+ (BOOL)validateWorkPhoneNumber:(NSString*)number {
if (number.length == 0) //删除操作
return YES;
int asciiCode = [number characterAtIndex:0];
if ((asciiCode >= 48 && asciiCode <= 57) || (asciiCode == 45))
return YES;
else
return NO;
}
+ (BOOL)validateIdentityNumber:(NSString*)number {
if (number.length == 0) //删除操作
return YES;
int asciiCode = [number characterAtIndex:0];
if ((asciiCode >= 48 && asciiCode <= 57) || (asciiCode == 88) || (asciiCode == 120))
return YES;
else
return NO;
}
+ (BOOL)validateOtherPapersNumber:(NSString*)number {
if (number.length == 0) //删除操作
return YES;
int asciiCode = [number characterAtIndex:0];
if ((asciiCode >= 48 && asciiCode <= 57) || (asciiCode == 87) || (asciiCode == 119))
return YES;
else
return NO;
}
+ (BOOL)validatePasswordNumber:(NSString*)number {
if (number.length == 0) //删除操作
return YES;
int asciiCode = [number characterAtIndex:0];
if ((asciiCode >= 48 && asciiCode <= 57) || (asciiCode == 71) || (asciiCode == 103)|| (asciiCode == 69) || (asciiCode == 101))
return YES;
else
return NO;
}
/**
* 验证身份证号,只能输入数字、“X”和“x”,共18个字符
*/
+ (BOOL)validateIdCard:(NSString*)idCard{
NSString *regex = @"^\\d{17}[0-9xX]$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if (![pred evaluateWithObject: idCard]) {
return NO;
}
return YES;
}
/**
* 验证护照号,只能输入"G加8位数字"或"E加8位数字",共9个字符
*/
+ (BOOL)validatePassportCard:(NSString*)passportNum{
NSString *regex = @"^[EG]\\d{8}$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if (![pred evaluateWithObject: passportNum]) {
return NO;
}
return YES;
}
/**
* 验证港澳通行证号,只能输入"W加8位数字"或"C加8位数字",共9个字符
*/
+ (BOOL)validateGangAoPassportNumber:(NSString*)GangAoPassportNumber{
NSString *regex = @"^[CW]\\d{8}$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if (![pred evaluateWithObject: GangAoPassportNumber]) {
return NO;
}
return YES;
}
/**
* 验证台胞证号,只能输入数字,共8个字符
*/
+ (BOOL)validate*PassportNumber:(NSString*)*PassportNumber{
NSString *regex = @"^\\d{8}$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if (![pred evaluateWithObject: *PassportNumber]) {
return NO;
}
return YES;
}
/**
* 验证军官证或警官证号,必须是以下两种格式中的一种
* 格式一:4到20位数字
* 格式二:位数 >=10&&<=20(中文按两位),并满足
* 1)必须有“字第”两字
* 2)“字第”前面有至少一个字符
* 3)“字第”后是4位以上数字
*/
+ (BOOL)validateLegalOfficerNumber:(NSString*)OfficerNumber{
// NSString *regex = @"^((\\d{4,20})|([\\u4e00-\\u9fa5]+字第(\\d+|\\d+-\\d+)))号?$";
// NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
// if (![pred evaluateWithObject: OfficerNumber]) {
// return NO;
// }
return YES;
}
/**
* 验证UAAP号,号码组成规则:学员姓名拼音+数字(防重名)+.+地区缩写,如tianyunan12.bj
*
*/
+ (BOOL)validateLegalUAAPNumber:(NSString*)UAAPNumber{
NSString *regex = @"^[a-zA-Z]+\\d+\\.[a-zA-Z]+$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if (![pred evaluateWithObject: UAAPNumber]) {
return NO;
}
return YES;
}
/**
* 验证纳税人识别码/统一社会信用代码
* 号码格式:
* ①验证纳税人识别码:6位行政区划码(纯数字)+ 9位组织机构代码(数字或大写字母)
* ②统一社会信用代码(18位):第1位(登记管理部门代码,数字或字母)、第2位(机构类别代码,数字或字母)
* 第3—8位(登记管理机关行政区划码,数字)、第9—17位(主体标识码,数字或字母)
* 第18位(校验码,数字或字母)
*/
+ (BOOL)validateTaxpayerNumber:(NSString*)TaxpayerNumber{
NSString *regex = @"^((\d{6}[0-9A-Z]{9})|([0-9A-Za-z]{2}\d{6}[0-9A-Za-z]{10}))$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if (![pred evaluateWithObject: TaxpayerNumber]) {
return NO;
}
return YES;
}
@end