iOS 驗證郵箱手機號格式

2022-09-06 17:54:06 字數 1370 閱讀 6276

做登入介面時,使用者在uitextfield中輸入輸入郵箱賬號後,我們應該在本地驗證格式是否正確,再將引數傳給伺服器驗證。

最簡單的就是利用系統的nspredicate

//利用正規表示式驗證

-(bool)isvalidateemail:(nsstring *)email ";

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

return [emailtest evaluatewithobject:email];

#import "nsstring+check.h"

@implementation nsstring (check)

-(bool)checkphonenuminput$";

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

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

nsstring * ct = @"^1((33|53|8[09])[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];

bool res1 = [regextestmobile evaluatewithobject:self];

bool res2 = [regextestcm evaluatewithobject:self];

bool res3 = [regextestcu evaluatewithobject:self];

bool res4 = [regextestct evaluatewithobject:self];

if (res1 || res2 || res3 || res4 )

return yes;

else

return no;

驗證郵箱和手機號

驗證郵箱和手機號 classname regularutil description date 2012 4 26下午06 21 54 public class regularutil 驗證是否是合法的密保答案 param answer 密保答案 return boolean 密保答案只能為數字 字...

手機號 電話號碼 郵箱 驗證

手機號 號碼 郵箱 驗證 public class validator return false public static boolean isnull object obj return false public static object get obj or empty object obj...

手機號 電話號碼 郵箱 驗證

手機號 號碼 郵箱 驗證 public class validator return false public static boolean isnull object obj return false public static object get obj or empty object obj...