//Validation email.
private boolean checkEmail(String email) {
String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(email);
if (!matcher.matches())
return false;
else
return true;
}
//Validation password
String passwordPattern ="[\\sA-Za-z0-9&().-]+";
Pattern pattern = Pattern.compile(passwordPattern);
//Validation postcode
Pattern pattern = Pattern.compile("\\d{1,6}");
Matcher matcher = pattern.matcher(postal);
//Validaton mobile
Pattern pattern = Pattern.compile("[0-9]{1,12}");
Matcher matcher = pattern.matcher(mobileNo);
- package test;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class TestPassword {
- public static void main(String args[]){
- String password="hahymfghdfg";
- Pattern p = Pattern.compile("[A-Z]+");
- Pattern q = Pattern.compile("[a-z]+");
- Pattern r = Pattern.compile("[0-9]+");
- Pattern s = Pattern.compile("\\p{Punct}+");
- Matcher m1 = p.matcher(password); //判断是否含有大写字符
- Matcher m2= q.matcher(password); //判断是否含有小写字符
- Matcher m3 = r.matcher(password);//判断是否含有数字
- Matcher m4 = s.matcher(password);//判断是否含有特殊字符
- if(m2.find(0)&&( !m4.find(0)) ){
- System.out.println("密码符合规则");
- }
- else{
- System.out.println("密码不符合规则");
- }
- }
- }