Java Regex Number Validate isNumeric(String number)

Here you can find the source of isNumeric(String number)

Description

is Numeric

License

LGPL

Declaration

public static boolean isNumeric(String number) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

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

public class Main {
    public static boolean isNumeric(String number) {
        boolean isValid = false;

        /*Number: A numeric value will have following format:
        ^[-+]?: Starts with an optional "+" or "-" sign.
        [0-9]*: May have one or more digits.
        \\.? : May contain an optional "." (decimal point) character.
        [0-9]+$ : ends with numeric digit.
         *//*  www.j  a va 2s . co m*/

        //Initialize reg ex for numeric data.
        String expression = "[0-9]*";
        CharSequence inputStr = number;
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(inputStr);

        if (matcher.matches()) {
            isValid = true;
        }

        return isValid;
    }
}

Related

  1. isNumberForLength(String numStr, int length)
  2. isNumberLiteral(String s)
  3. isNumberOfShownValue(String inputString)
  4. isNumeric(String as_argument)
  5. isNumeric(String input)
  6. isNumeric(String s)
  7. isNumeric(String str)
  8. isNumeric(String str)
  9. isNumeric(String str)