电话、邮箱、QQ正则表达式(Android)
2017-03-31 16:31
295 查看
在做项目的时候,输入信息相关的地方少不了要进行信息校验,我总结了一下我用到的校验方式
电话 (11位号码)如:135********
public static boolean regexPhoneNumber(String phoneNum) {
// 电话号码匹配结果
boolean isPhoneNum_matcher = phoneNum.matches("1[34578]\\d{9}");
// 如果isPhoneNum_matcher is true , 则return true , else return false
if (isPhoneNum_matcher)
return true;
return false;
}
邮箱
QQ
/**
*
* param qqNum
* 传入的QQ
* return 如果匹配正确,return true, else return false
*/
public static boolean regexQQNumber(String qqNum) {
// QQ号匹配结果
boolean isQQNum_matcher = qqNum.matches("[1-9]\\d{2,11}");
if (isQQNum_matcher)
return true;
return false;
}
邮编
public static boolean checkpostalcode(String postalcode) {
boolean ispostalcode_matcher = postalcode.matches("[1-9]\\d{5}(?!\\d)");
if (ispostalcode_matcher)
return true;
return false;
}
IC Card
public static boolean checkICCard(String cardNumber) {
boolean iscardNumber_matcher = cardNumber.matches("[1-9]\\d{5}(?!\\d)");
if (iscardNumber_matcher)
return true;
return false;
}
对于6到20位包含几种特殊字符(!#%*等)密码 的验证
public static boolean regexPassWord(String pwd) {
// 密码匹配结果
// boolean isPassWord_matcher = pwd.matches("^([A-Z]|[a-z]|[0-9]){6,20}$");
//^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,22}$
boolean isPassWord_matcher = pwd.matches("^[\\@A-Za-z0-9\\!\\#\\$\\%\\^\\&\\*\\.\\~]{6,20}$");
if (isPassWord_matcher)
return true;
return false;
}
电话 (11位号码)如:135********
public static boolean regexPhoneNumber(String phoneNum) {
// 电话号码匹配结果
boolean isPhoneNum_matcher = phoneNum.matches("1[34578]\\d{9}");
// 如果isPhoneNum_matcher is true , 则return true , else return false
if (isPhoneNum_matcher)
return true;
return false;
}
邮箱
/** * 邮箱正则验证:"[a-zA-Z_0-9]+@[a-zA-Z0-9]+(\\.[a-zA-Z]{2,}){1,3}" '@'号前没有点'.' * 邮箱正则验证:"^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$" '@'号前有点'.' * * param email * 传入的参数仅仅是一个邮箱地址时,调用此方法 * return 如果匹配正确,return true , else return false */ // 如果传进来的是邮箱地址,则对邮箱进行正则匹配 public static boolean regexEmailAddress(String email) { // 邮箱匹配结果 boolean isEmail_matcher = email.matches("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"); // 如果isEmail_matcher value is true , 则 return true , else return false if (isEmail_matcher) return true; return false; }
/**
*
* param qqNum
* 传入的QQ
* return 如果匹配正确,return true, else return false
*/
public static boolean regexQQNumber(String qqNum) {
// QQ号匹配结果
boolean isQQNum_matcher = qqNum.matches("[1-9]\\d{2,11}");
if (isQQNum_matcher)
return true;
return false;
}
邮编
public static boolean checkpostalcode(String postalcode) {
boolean ispostalcode_matcher = postalcode.matches("[1-9]\\d{5}(?!\\d)");
if (ispostalcode_matcher)
return true;
return false;
}
IC Card
public static boolean checkICCard(String cardNumber) {
boolean iscardNumber_matcher = cardNumber.matches("[1-9]\\d{5}(?!\\d)");
if (iscardNumber_matcher)
return true;
return false;
}
对于6到20位包含几种特殊字符(!#%*等)密码 的验证
public static boolean regexPassWord(String pwd) {
// 密码匹配结果
// boolean isPassWord_matcher = pwd.matches("^([A-Z]|[a-z]|[0-9]){6,20}$");
//^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,22}$
boolean isPassWord_matcher = pwd.matches("^[\\@A-Za-z0-9\\!\\#\\$\\%\\^\\&\\*\\.\\~]{6,20}$");
if (isPassWord_matcher)
return true;
return false;
}
相关文章推荐
- javascript:验证邮箱、电话、QQ的正则表达式
- 邮箱手机电话正则表达式
- Android TextView通过Spannable识别超链接、邮箱、电话
- Android中调用手机邮箱 手机短信 手机电话
- Android读取联系人信息(姓名,电话,地址,邮箱,生日等)
- 正则表达式 验证 电话,手机,邮箱,数字
- Android 仿QQ首页的消息和电话的切换(Viewpager+frgment)
- android从自己的应用打开邮箱和QQ
- Android 仿QQ首页的消息和电话的切换,首页的头部(完全用布局控制)
- Android开发:使用Intent打开电话、短信、邮箱、本地文件等系统应用程序整理大全
- android之邮箱注册正则表达式
- Android注册功能--电话验证和邮箱验证
- 正则表达式之电话,邮箱,邮编篇
- [置顶] Android 仿QQ首页的消息和电话的切换(Viewpager+frgment)
- android获取手机联系人信息(电话,邮箱,姓名,头像)
- javascript:验证邮箱、电话、QQ的正则表达式
- 正则表达式验证邮箱,qq,电话
- 身份证,联系电话,邮箱,网址,邮编,传真号码,MSN,国籍和身份证,QQ和电话校验
- android 判断 手机号码、邮编、Email邮箱、是否正确还有qq号
- Android 仿QQ首页的消息和电话的切换,首页的头部(完全用布局控制)