Java Regex Number Validate isNumberForLength(String numStr, int length)

Here you can find the source of isNumberForLength(String numStr, int length)

Description

is Number For Length

License

Apache License

Declaration

public static boolean isNumberForLength(String numStr, int length) 

Method Source Code

//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());
    }
}

Related

  1. isNumber(String str, String sign)
  2. isNumber(String value)
  3. isNumber(String value)
  4. isNumber(String value)
  5. isNumber_Lowerletter_Underline(String str)
  6. isNumberLiteral(String s)
  7. isNumberOfShownValue(String inputString)
  8. isNumeric(String as_argument)
  9. isNumeric(String input)