手機號驗證
//手機號以13, 15,18開頭,八個 \d 數字字元
nsstring *phoneregex = @"^((13[0-9])|(15[^4,\\d])|(18[0,0-9]))\\d$";
nspredicate *phonetest = [nspredicate predicatewithformat:@"self matches %@",phoneregex];
return [phonetest evaluatewithobject:mobile];
手機號歸屬驗證
密碼格式驗證
// 正則匹配使用者密碼6-18位數字和字母組合
+ (bool)checkpassword:(nsstring*) password
";nspredicate*pred = [nspredicatepredicatewithformat:@"self matches %@",pattern];
boolismatch = [predevaluatewithobject:password];
returnismatch;
}
使用者名稱格式驗證正則匹配使用者姓名,20位的中文或英文
+ (bool)checkusername : (nsstring*) username
";nspredicate*pred = [nspredicatepredicatewithformat:@"self matches %@",pattern];
boolismatch = [predevaluatewithobject:username];
returnismatch;
}
郵箱驗證+ (bool) validateemail:(nsstring *)email
"; nspredicate *emailtest = [nspredicate predicatewithformat:@"self matches %@", emailregex];
return [emailtest evaluatewithobject:email];
}
銀行卡號驗證+ (bool)isbankcard:(nsstring *)cardno
nsinteger oddsum = 0; //奇數求和
nsinteger evensum = 0; //偶數求和
nsinteger allsum = 0;
nsinteger cardnolength = (nsinteger)[cardno length];
// 取了最後一位數
nsinteger lastnum = [[cardno substringfromindex:cardnolength-1] intvalue];
//測試的是除了最後一位數外的其他數字
cardno = [cardno substringtoindex:cardnolength - 1];
for (nsinteger i = cardnolength -1 ; i>=1;i--) else
}elseelse}}
allsum = oddsum + evensum;
allsum += lastnum;
if((allsum % 10) == 0)
return
yes;
else
return
no;}
銀行卡號所屬銀行驗證+(nsstring *)bankofcard:(nsstring *)cardnumelse
if (dicbank[strprefour])else
if (dicbank[strprefive])else
if (dicbank[strpresix])else
if (dicbank[strpreseven])else
if (dicbank[strpreeight])else
if (dicbank[strprenine])else
if (dicbank[strpreten])else
nsrange range =[strbankinfo rangeofstring:@" "];
nsstring *bankname = [strbankinfo substringtoindex:range.location];
return bankname;
}+(nsstring *)getprefixstringtoindex:(nsinteger)index fromstring:(nsstring *)strallelse
}
身份證號驗證+ (bool) validateidentitycard: (nsstring *)identitycard
nsstring *regex2 = @"^(\\d|\\d)(\\d|[xx])$";
nspredicate *identitycardpredicate = [nspredicate predicatewithformat:@"self matches %@",regex2];
return [identitycardpredicate evaluatewithobject:identitycard];
}
車牌號驗證//車牌號驗證
+ (bool) validatecarno:(nsstring *)carno
[a-za-z][a-za-z_0-9][a-za-z_0-9_\u4e00-\u9fa5]$";
nspredicate *cartest = [nspredicate predicatewithformat:@"self matches %@",carregex];
nslog(@"cartest is %@",cartest);
return [cartest evaluatewithobject:carno];
}
銀行卡號歸屬行驗證檔案: Python中常用字串處理
s 你好,hello len s 8 s 0 你 username mark password payayawhip s password is format username,password mark s password is payayawhip si suffixes kb mb gb t...
python中常用字串
轉義字元 因為一些特殊字元是python中的關鍵字或一些特殊的概念如換行。所以以特殊字元 開頭。構造轉義字元。n 換行 t 製表符 單引號 雙引號 反斜槓 for i in abc print i a b c hello 4 0 了解 字串 count 子字串 搜尋子串出現次數 xyaxyaxy c...
Python中常用字串 函式
在 python 有各種各樣的string操作函式。在歷史上string類在 python 中經歷了一段輪迴的歷史。在最開始的時候,python 有乙個專門的string的module,要使用string的方法要先import,但後來由於眾多的 python 使用者的建議,從 python 2.0開...