Java Regular Expression match password

Description

Java Regular Expression match password


import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) throws Exception {
        String password = "asdfasdf";
        System.out.println(checkPwd(password));
    }//  w  w w .ja va 2s  . c  om

    public static boolean checkPwd(String password) {
        String reg = "[a-zA-Z0-9]+";
        return startCheck(reg, password);
    }

    public static boolean startCheck(String reg, String string) {
        boolean tem = false;

        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(string);

        tem = matcher.matches();
        return tem;
    }
}



PreviousNext

Related