iOS_正則表達(dá)式判斷手機(jī)型號梁只、郵箱缚柳、手機(jī)號、身份證搪锣、昵稱秋忙、密碼等

//郵箱

+ (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];

}

//手機(jī)號碼驗(yàn)證

- (BOOL)validateMobile{

NSString *MOBILE = @"^1[34578]\\d{9}$";

NSPredicate *regexTestMobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE];

if ([regexTestMobile evaluateWithObject:self]) {

return YES;

}else {

return NO;

}


//車牌號驗(yàn)證

+ (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];

}


//判斷是否有特殊符號

- (BOOL)effectivePassword

{

//? ? NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"&\"< >\\/*/null & /* /NULL"];

//? ? NSString *trimmedString = [self stringByTrimmingCharactersInSet:set];

//? ? return trimmedString;

NSString *regex = @"[a-zA-Z0-9]{6,20}";

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];

return [predicate evaluateWithObject:self];

}

//判斷手機(jī)型號

+ (NSString *)deviceString

{

// 需要#import "sys/utsname.h"

struct utsname systemInfo;

uname(&systemInfo);

NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];

if ([deviceString isEqualToString:@"iPhone1,1"])? ? return @"iPhone 1G";

if ([deviceString isEqualToString:@"iPhone1,2"])? ? return @"iPhone 3G";

if ([deviceString isEqualToString:@"iPhone2,1"])? ? return @"iPhone 3GS";

if ([deviceString isEqualToString:@"iPhone3,1"])? ? return @"iPhone 4";

if ([deviceString isEqualToString:@"iPhone3,3"])? ? return @"Verizon iPhone 4";

if ([deviceString isEqualToString:@"iPhone4,1"])? ? return @"iPhone 4S";

if ([deviceString isEqualToString:@"iPhone5,1"])? ? return @"iPhone 5 (GSM)";

if ([deviceString isEqualToString:@"iPhone5,2"])? ? return @"iPhone 5 (GSM+CDMA)";

if ([deviceString isEqualToString:@"iPhone5,3"])? ? return @"iPhone 5c (GSM)";

if ([deviceString isEqualToString:@"iPhone5,4"])? ? return @"iPhone 5c (GSM+CDMA)";

if ([deviceString isEqualToString:@"iPhone6,1"])? ? return @"iPhone 5s (GSM)";

if ([deviceString isEqualToString:@"iPhone6,2"])? ? return @"iPhone 5s (GSM+CDMA)";

if ([deviceString isEqualToString:@"iPhone7,2"])? ? return @"iPhone 6";

if ([deviceString isEqualToString:@"iPhone7,1"])? ? return @"iPhone 6 Plus";

if ([deviceString isEqualToString:@"iPod1,1"])? ? ? return @"iPod Touch 1G";

if ([deviceString isEqualToString:@"iPod2,1"])? ? ? return @"iPod Touch 2G";

if ([deviceString isEqualToString:@"iPod3,1"])? ? ? return @"iPod Touch 3G";

if ([deviceString isEqualToString:@"iPod4,1"])? ? ? return @"iPod Touch 4G";

if ([deviceString isEqualToString:@"iPod5,1"])? ? ? return @"iPod Touch 5G";

if ([deviceString isEqualToString:@"iPad1,1"])? ? ? return @"iPad";

if ([deviceString isEqualToString:@"iPad2,1"])? ? ? return @"iPad 2 (WiFi)";

if ([deviceString isEqualToString:@"iPad2,2"])? ? ? return @"iPad 2 (GSM)";

if ([deviceString isEqualToString:@"iPad2,3"])? ? ? return @"iPad 2 (CDMA)";

if ([deviceString isEqualToString:@"iPad2,4"])? ? ? return @"iPad 2 (WiFi)";

if ([deviceString isEqualToString:@"iPad2,5"])? ? ? return @"iPad Mini (WiFi)";

if ([deviceString isEqualToString:@"iPad2,6"])? ? ? return @"iPad Mini (GSM)";

if ([deviceString isEqualToString:@"iPad2,7"])? ? ? return @"iPad Mini (GSM+CDMA)";

if ([deviceString isEqualToString:@"iPad3,1"])? ? ? return @"iPad 3 (WiFi)";

if ([deviceString isEqualToString:@"iPad3,2"])? ? ? return @"iPad 3 (GSM+CDMA)";

if ([deviceString isEqualToString:@"iPad3,3"])? ? ? return @"iPad 3 (GSM)";

if ([deviceString isEqualToString:@"iPad3,4"])? ? ? return @"iPad 4 (WiFi)";

if ([deviceString isEqualToString:@"iPad3,5"])? ? ? return @"iPad 4 (GSM)";

if ([deviceString isEqualToString:@"iPad3,6"])? ? ? return @"iPad 4 (GSM+CDMA)";

if ([deviceString isEqualToString:@"iPad4,1"])? ? ? return @"iPad Air (WiFi)";

if ([deviceString isEqualToString:@"iPad4,2"])? ? ? return @"iPad Air (Cellular)";

if ([deviceString isEqualToString:@"iPad4,3"])? ? ? return @"iPad Air";

if ([deviceString isEqualToString:@"iPad4,4"])? ? ? return @"iPad Mini 2G (WiFi)";

if ([deviceString isEqualToString:@"iPad4,5"])? ? ? return @"iPad Mini 2G (Cellular)";

if ([deviceString isEqualToString:@"iPad4,6"])? ? ? return @"iPad Mini 2G";

if ([deviceString isEqualToString:@"iPad4,7"])? ? ? return @"iPad Mini 3 (WiFi)";

if ([deviceString isEqualToString:@"iPad4,8"])? ? ? return @"iPad Mini 3 (Cellular)";

if ([deviceString isEqualToString:@"iPad4,9"])? ? ? return @"iPad Mini 3 (China)";

if ([deviceString isEqualToString:@"iPad5,3"])? ? ? return @"iPad Air 2 (WiFi)";

if ([deviceString isEqualToString:@"iPad5,4"])? ? ? return @"iPad Air 2 (Cellular)";

if ([deviceString isEqualToString:@"AppleTV2,1"])? return @"Apple TV 2G";

if ([deviceString isEqualToString:@"AppleTV3,1"])? return @"Apple TV 3";

if ([deviceString isEqualToString:@"AppleTV3,2"])? return @"Apple TV 3 (2013)";

if ([deviceString isEqualToString:@"i386"])? ? ? ? return @"Simulator";

if ([deviceString isEqualToString:@"x86_64"])? ? ? return @"Simulator";

NSLog(@"NOTE: Unknown device type: %@", deviceString);

return deviceString;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市构舟,隨后出現(xiàn)的幾起案子灰追,更是在濱河造成了極大的恐慌,老刑警劉巖狗超,帶你破解...
    沈念sama閱讀 206,311評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件弹澎,死亡現(xiàn)場離奇詭異,居然都是意外死亡努咐,警方通過查閱死者的電腦和手機(jī)苦蒿,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,339評論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來渗稍,“玉大人佩迟,你說我怎么就攤上這事「鸵伲” “怎么了报强?”我有些...
    開封第一講書人閱讀 152,671評論 0 342
  • 文/不壞的土叔 我叫張陵,是天一觀的道長拱燃。 經(jīng)常有香客問我秉溉,道長,這世上最難降的妖魔是什么碗誉? 我笑而不...
    開封第一講書人閱讀 55,252評論 1 279
  • 正文 為了忘掉前任召嘶,我火速辦了婚禮,結(jié)果婚禮上哮缺,老公的妹妹穿的比我還像新娘苍蔬。我一直安慰自己,他們只是感情好蝴蜓,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,253評論 5 371
  • 文/花漫 我一把揭開白布碟绑。 她就那樣靜靜地躺著俺猿,像睡著了一般。 火紅的嫁衣襯著肌膚如雪格仲。 梳的紋絲不亂的頭發(fā)上押袍,一...
    開封第一講書人閱讀 49,031評論 1 285
  • 那天,我揣著相機(jī)與錄音凯肋,去河邊找鬼谊惭。 笑死,一個胖子當(dāng)著我的面吹牛侮东,可吹牛的內(nèi)容都是我干的圈盔。 我是一名探鬼主播,決...
    沈念sama閱讀 38,340評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼悄雅,長吁一口氣:“原來是場噩夢啊……” “哼驱敲!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起宽闲,我...
    開封第一講書人閱讀 36,973評論 0 259
  • 序言:老撾萬榮一對情侶失蹤众眨,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后容诬,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體娩梨,經(jīng)...
    沈念sama閱讀 43,466評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,937評論 2 323
  • 正文 我和宋清朗相戀三年览徒,在試婚紗的時候發(fā)現(xiàn)自己被綠了狈定。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,039評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡习蓬,死狀恐怖纽什,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情友雳,我是刑警寧澤稿湿,帶...
    沈念sama閱讀 33,701評論 4 323
  • 正文 年R本政府宣布铅匹,位于F島的核電站押赊,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏包斑。R本人自食惡果不足惜流礁,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,254評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望罗丰。 院中可真熱鬧神帅,春花似錦、人聲如沸萌抵。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,259評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至霎桅,卻和暖如春栖疑,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背滔驶。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評論 1 262
  • 我被黑心中介騙來泰國打工遇革, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人揭糕。 一個月前我還...
    沈念sama閱讀 45,497評論 2 354
  • 正文 我出身青樓萝快,卻偏偏與公主長得像,于是被迫代替她去往敵國和親著角。 傳聞我的和親對象是個殘疾皇子揪漩,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,786評論 2 345

推薦閱讀更多精彩內(nèi)容