check Password with regex, only number and letter, length 6-10 - Java java.util.regex

Java examples for java.util.regex:Match Password

Description

check Password with regex, only number and letter, length 6-10

Demo Code


//package com.java2s;

import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) throws Exception {
        String password = "java2s.com";
        System.out.println(checkPassword(password));
    }//from  www .  ja  v a 2s. co m

    public static boolean checkPassword(String password) {
        String regex = "^[0-9a-zA-Z]{6,10}$";
        return Pattern.matches(regex, password);
    }
}

Related Tutorials