Here you can find the source of isNumberForLength(String numStr, int length)
public static boolean isNumberForLength(String numStr, int length)
//package com.java2s; //License from project: Apache License import java.util.regex.Pattern; public class Main { public static boolean isNumberForLength(String numStr, int length) { String regex = "[0-9]{" + length + "}"; return numStr != null && Pattern.matches(regex, numStr); }//from w ww .j ava 2 s. c o m public static boolean isNumberForLength(String numStr) { if (numStr == null) { return false; } return isNumberForLength(numStr, numStr.length()); } }