iphone 註冊校驗(正則)

2021-08-31 20:14:22 字數 2693 閱讀 2191

最近在做使用者管理程式,在做的過程中使用者註冊資訊校驗在網上查了好久,沒查到現成的**,只能自己寫了,
**放在這裡,有需要直接拿去。自己也做備份,以後使用方便。
//校驗使用者名稱

+ (bool) validateusername : (nsstring *) str

$|.|^[^a-za-z0-9\u4e00-\u9fa5]|[^\\w\u4e00-\u9fa5.-]|([_.-])\1"];

nsregularexpression *regularexpression = [[nsregularexpression alloc]

initwithpattern:patternstr

options:nsregularexpressioncaseinsensitive

error:nil];

nsuinteger numberofmatch = [regularexpression numberofmatchesinstring:str

options:nsmatchingreportprogress

range:nsmakerange(0, str.length)];

[regularexpression release];

if(numberofmatch > 0)

return no;

}//校驗使用者密碼

+ (bool) validateuserpasswd : (nsstring *) str

$" options:nsregularexpressioncaseinsensitive

error:nil];

nsuinteger numberofmatch = [regularexpression numberofmatchesinstring:str

options:nsmatchingreportprogress

range:nsmakerange(0, str.length)];

[regularexpression release];

if(numberofmatch > 0)

nslog(@"%@ isnumbericstring: no", str);

return no;

}//校驗使用者生日

+ (bool) validateuserborndate : (nsstring *) str

)-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d)-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d)-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$";

nsregularexpression *regularexpression = [[nsregularexpression alloc]

initwithpattern:patternstr

options:nsregularexpressioncaseinsensitive

error:nil];

nsuinteger numberofmatch = [regularexpression numberofmatchesinstring:str

options:nsmatchingreportprogress

range:nsmakerange(0, str.length)];

[regularexpression release];

if(numberofmatch > 0)

nslog(@"%@ isnumbericstring: no", str);

return no;

}//校驗使用者手機號碼

+ (bool) validateuserphone : (nsstring *) str

)|^((\\d)|(\\d|\\d)-(\\d)|(\\d|\\d)-(\\d)-(\\d|\\d|\\d|\\d)|(\\d)-(\\d|\\d|\\d|\\d))$)"

options:nsregularexpressioncaseinsensitive

error:nil];

nsuinteger numberofmatch = [regularexpression numberofmatchesinstring:str

options:nsmatchingreportprogress

range:nsmakerange(0, str.length)];

[regularexpression release];

if(numberofmatch > 0)

nslog(@"%@ isnumbericstring: no", str);

return no;

}//校驗使用者郵箱

+ (bool) validateuseremail : (nsstring *) str

nslog(@"%@ isnumbericstring: no", str);

return no;

}

iphone 常用校驗表單

1 判斷使用者名稱,在2 16位 bool checkinput nsstring text nspredicate emailtest nspredicate predicatewithformat self matches regex return emailtest evaluatewitho...

使用者註冊常用校驗

校驗詳情 1.每個輸入框,滑鼠移入,移出時,跟隨浮出資訊提示 正確的資料輸入格式 2.每個輸入框,輸入資料時,格式錯誤,輸入框變紅,輸入框後給出紅色文字提示 輸入正確時,輸入框變回之前樣式,錯誤提示文字消失 3.全部輸入完畢或不輸入任何資料直接點 註冊 按鈕時,對輸入框,從上至下依次校驗,如果全部正...

正則校驗url

http s?複雜點為 var urlregex http https w w w u4e00 u9fa5 或 http https w w w w 當然這三種寫法不夠嚴謹,與 等明顯錯誤的url依然能匹配成功。下面是比較嚴謹的一些寫法 涉及對http,https協議,網域名稱,ip,port的校驗...