iOS註冊驗證

2021-07-10 22:02:20 字數 2885 閱讀 9980

出處:

//驗證電子郵件

- (bool)isemail";

nspredicate *predicate = [nspredicate predicatewithformat:

@"self matches %@"

, emailregex];

return

[predicate 

evaluatewithobject:

self];

}//驗證手機號

- (bool)ismobilephonenumber$";

nsstring

* cm = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[2378])\\d)\\d$";

nsstring

* cu = @"^1(3[0-2]|5[256]|8[56])\\d$";

nsstring

* ct = @"^1((33|53|8[019])[0-9]|349)\\d$";

// nsstring * phs = @"^0(10|2[0-5789]|\\d)\\d$";

nspredicate *regextestmobile = [nspredicate predicatewithformat:

@"self matches %@"

, mobile];

nspredicate *regextestcm = [nspredicate predicatewithformat:

@"self matches %@"

, cm];

nspredicate *regextestcu = [nspredicate predicatewithformat:

@"self matches %@"

, cu];

nspredicate *regextestct = [nspredicate predicatewithformat:

@"self matches %@"

, ct];

if (([regextestmobile evaluatewithobject:self] == yes)

|| ([regextestcm evaluatewithobject:self] == yes)

|| ([regextestct evaluatewithobject:self] == yes)

|| ([regextestcu evaluatewithobject:self] == yes))

else

}//驗證是否是數字

- (bool)isnumber

return yes; }

//驗證車牌號

- (bool)isplatenumber[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:

self];

}//驗證ip位址

- (bool)isipaddress

//驗證埠號

- (bool)isport|[1-6][0-5][0-5][0-3][0-5])$";

nspredicate *pred = [nspredicate predicatewithformat:

@"self matches %@"

,regex];

return

[pred evaluatewithobject:

self];

}//驗證網域名稱

- (bool)isurl|ftp)://[a-za-z0-9\\.\\-]+\\.([a-za-z])(:\\d+)?(/[a-za-z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-za-z0-9\\.\\-]+\\.([a-za-z])(:\\d+)?(/[a-za-z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)";

nspredicate *pred = [nspredicate predicatewithformat:

@"self matches %@"

, regex];

return

[pred evaluatewithobject:

self];

}//驗證身份證號

- (bool)isidnumber

nsstring

*regex2 = @"^(\\d|\\d)(\\d|[xx])$";

nspredicate *identitycardpredicate = [nspredicate

predicatewithformat:@"self matches %@",regex2];

return [identitycardpredicate evaluatewithobject:self];

}//驗證密碼

- (bool)ispassword+$";

nspredicate *passwordpredicate = [nspredicate

predicatewithformat:@"self matches %@",passwordregex];

return [passwordpredicate evaluatewithobject:self];

}//正常字元包括中文,英文,數字,下劃線

- (bool)isnotnontainsspecialcharacters

登入註冊 註冊輸入驗證

上次講了登入註冊問題的資料庫表怎麼建,以及具體有哪些內容。今天主要講一下註冊的表單驗證。我們經常上網各種登入註冊的時候應該已經注意過就是有時候密碼有要求,比如輸入6 20位密碼。還有確認密碼,必須和密碼輸入一致的時候才行。郵箱也是,郵箱的格式不能出錯。當以上格式有誤的時候就不能提交表單,還有如果還有...

js註冊驗證

通過js控制註冊,上 js 註冊前台驗證 var formobj checkemail function name,msg else return false checkpassword function name,msg else return false checknull function n...

js註冊驗證

function getfocus 設定使用者名稱文字框獲取焦點 function checkname 檢查使用者名稱 for var i 0 i 0 text a text z text a text z text if i myname.length function checkuserpass...