import java.util.regex.Pattern; public class Test_REG { public static void main(String[] args) { //只允许输入6位数字 String pattern = "[0-9]{6}"; boolean isMatch = Pattern.matches(pattern, "123456"); System.out.println(isMatch); } }
import java.util.regex.Pattern; public class Test_REG { public static void main(String[] args) { //只允许输入6位数字 String pattern = "[0-9]{6}"; boolean isMatch = Pattern.matches(pattern, "123456"); System.out.println(isMatch); } }
转载于:https://www.cnblogs.com/lxcmyf/p/8672094.html