身份證號碼驗證正規表示式
需要乙個簡單的驗證身份證號的正規表示式,從網上查了很多,都有問題,主要是只要超過15位,都能夠通過,於是自己查了半天手冊,寫了下面這個式子,能夠滿足簡單的要求:
1、15位或18位,如果是15位,必需全是數字。
2、如果是18位,最後一位可以是數字或字母xx,其餘必需是數字。
/^(\d$|^\d$|^\d(\d|x|x))$/
從這個表示式想到的:
1、正規表示式首先是要通過正確的
2、限制不正確
3、可以不限制其中的某此規則,但一定要讓正確的先通過。
//郵箱
+ (bool) validateemail:(nsstring *)email
";nspredicate *emailtest = [nspredicate predicatewithformat:@"self matches %@", emailregex];
return [emailtest evaluatewithobject:email];
}//手機號碼驗證
+ (bool) validatemobile:(nsstring *)mobile
$";nspredicate *phonetest = [nspredicate predicatewithformat:@"self matches %@",phoneregex];
return [phonetest evaluatewithobject:mobile];
}//車牌號驗證
+ (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];
}//車型
+ (bool) validatecartype:(nsstring *)cartype
//使用者名稱
+ (bool) validateusername:(nsstring *)name
+$";
nspredicate *usernamepredicate = [nspredicate predicatewithformat:@"self matches %@",usernameregex];
bool b = [usernamepredicate evaluatewithobject:name];
return b;
}//密碼
+ (bool) validatepassword:(nsstring *)password
+$";
nspredicate *passwordpredicate = [nspredicate predicatewithformat:@"self matches %@",passwordregex];
return [passwordpredicate evaluatewithobject:password];
}//暱稱
+ (bool) validatenickname:(nsstring *)nickname
$";nspredicate *passwordpredicate = [nspredicate predicatewithformat:@"self matches %@",nicknameregex];
return [passwordpredicate evaluatewithobject:nickname];
}//身份證號
+ (bool) validateidentitycard: (nsstring *)identitycard
nsstring *regex2 = @"^(//d|//d)(//d|[xx])$";
nspredicate *identitycardpredicate = [nspredicate predicatewithformat:@"self matches %@",regex2];
return [identitycardpredicate evaluatewithobject:identitycard];}
java js 各種正則
先學習基本規則 有點枯燥,可以參考下 正規表示式 教程 菜鳥教程 正規表示式驗證工具類 開源中國社群 自己用過的 1,校驗手機號 regularexp 13 0 9 15 012356789 17 678 18 0 9 14 57 0 9 簡單版1 只校驗為11位數字 regularexp 0 9 ...
各種正則判斷(前端)
匹配表情 u0020 u007e u00a0 u00be u2e80 ua4cf uf900 ufaff ufe30 ufe4f uff00 uffef u0080 u009f u2000 u201f u2026 u2022 u20ac r n g 匹配只能輸入中文或英文或者數字 u4e00 u9f...
各種input相關操作
1.radio 選擇被選中的radio input radio checked 2.select 選中指定value的option select name select1 value 1 attr selected true 注意上面 中有空格 3.checkbox 選中制定value的checkb...