同时支持手机号、用户名、邮箱登录
2014-08-27 13:55
423 查看
创建项目:
测试的代码:
public static void main(String[] args) {
//String e = "257@qq.com";
String e ="15315315326";
String em = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
//String ph = " ^[1][358][0-9]{9}$";
String ph = "^[1][3578]\\d{9}$";
//Pattern pemail = Pattern.compile("em");
System.out.println(e.matches(em));
System.out.println(e.matches(ph));
if(e.matches(em)){//邮箱登录
System.out.println("you想");
} else if(e.matches(ph)){//手机号登录
System.out.println("手机红啊");
}else{//就是用户名登录
System.out.println("用户名");
}
}
3
项目中的使用:
//判断用户的登录方式
String loginmethod = webParams.reqString("phone");
String em = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
String ph = "^[1][3578]\\d{9}$";
if(loginmethod.matches(em)){//邮箱登录
userGetMap.put("email", loginmethod);
} else if(loginmethod.matches(ph)){//手机号登录
userGetMap.put("phone", webParams.reqString("phone"));
}else{//就是用户名登录
userGetMap.put("username", webParams.reqString("phone"));
}
DbResultMap userObj = dao.selectObj(UserBiz.USER_GET, userGetMap);
测试的代码:
public static void main(String[] args) {
//String e = "257@qq.com";
String e ="15315315326";
String em = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
//String ph = " ^[1][358][0-9]{9}$";
String ph = "^[1][3578]\\d{9}$";
//Pattern pemail = Pattern.compile("em");
System.out.println(e.matches(em));
System.out.println(e.matches(ph));
if(e.matches(em)){//邮箱登录
System.out.println("you想");
} else if(e.matches(ph)){//手机号登录
System.out.println("手机红啊");
}else{//就是用户名登录
System.out.println("用户名");
}
}
3
项目中的使用:
//判断用户的登录方式
String loginmethod = webParams.reqString("phone");
String em = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
String ph = "^[1][3578]\\d{9}$";
if(loginmethod.matches(em)){//邮箱登录
userGetMap.put("email", loginmethod);
} else if(loginmethod.matches(ph)){//手机号登录
userGetMap.put("phone", webParams.reqString("phone"));
}else{//就是用户名登录
userGetMap.put("username", webParams.reqString("phone"));
}
DbResultMap userObj = dao.selectObj(UserBiz.USER_GET, userGetMap);
相关文章推荐
- 简单实现支持用户名和邮箱登录
- Ecshop支持用户名、邮箱或手机号码登录
- flask实现同时使用用户名/邮箱其一进行登录
- 数据库按照手机号分库后,还需要允许用户使用邮箱、用户名等登录,怎么才能提高查询效率?
- 怎么实现使用手机号、邮箱、用户名登录
- 实现用户名、邮箱、手机号三种都可以登录
- app中使用用户名/邮箱/手机号登录的思路分析
- thinkphp 手机号和用户名同时登录
- thinkphp 手机号和用户名同时登录
- 手机号、邮箱或者用户名登录的实现方法
- ECSHOP同时使用用户名、邮箱、手机号码登录
- 使用正则表达式验证注册页面(用户名,密码,确认密码,邮箱,手机号)
- 通过SessionID和用户名来保证同一个用户不能同时登录
- android 登录推断是否邮箱或手机号
- iOS:判断用户名是否以字母开头、手机号输入、邮箱是否正确的正则表达式
- 通过SessionID和用户名来保证同一个用户不能同时登录
- Spring Security实现用户名或者手机号登录
- 让WINXP(SP2)支持多用户同时登录
- django如何用邮箱代替用户名登录
- JavaScript正则表达式 匹配邮箱、手机号、日期、用户名、密码、身份证等