ios 判斷數字大小 iOS判斷漢字個數

2021-10-18 19:11:03 字數 1007 閱讀 9725

最近在做註冊登陸的認證,需求:

使用者名為6~12位「字元」

也就是說,乙個英文是乙個字元,乙個中文是兩個字元,用正規表示式好像不容易實現吧?

沒什麼好說的,直接上答案了:

判斷字元數

//判斷字串為6~12位「字元」

- (bool)isvalidatename:(nsstring *)nameelseelse";

nspredicate *emailtest = [nspredicate predicatewithformat:@"self matches %@", emailregex];

return [emailtest evaluatewithobject:email];

判斷密碼為6~20位字元

- (bool)isvalidatepassword:(nsstring *)password$";

nspredicate *pred = [nspredicate predicatewithformat:@"self matches %@", regex];

return [pred evaluatewithobject:password];

判斷手機格式

+ (bool)checktel:(nsstring *)str";//手機號碼變化大,所以沒有做更精確

nspredicate *pred = [nspredicate predicatewithformat:@"self matches %@", regex];

return [pred evaluatewithobject:str];;

判斷郵編格式為6位數字

+ (bool)checkpostcode:(nsstring *)str$";

nspredicate *pred = [nspredicate predicatewithformat:@"self matches %@", regex];

return [pred evaluatewithobject:str];

如果有什麼不正確的地方,歡迎指導!

iOS網路判斷

執行應用時先進行網路判斷,判斷目前處於什麼網路下,判斷步驟如下 2.匯入標頭檔案 import afnetworkreachabilitymanager.h 3.實現 1.獲得網路監控的管理者 afnetworkreachabilitymanager manager afnetworkreachab...

iOS判斷網路

1.afnnetworking afn 判斷網路 void getinternetstatue if status afnetworkreachabilitystatusreachableviawwan status afnetworkreachabilitystatusreachableviawi...

判斷 iOS 系統版本

system versioning preprocessor macros define system version equal to v uidevice currentdevice systemversion compare v options nsnumericsearch nsordere...