Java Regex Number Validate isNumber(String value)

Here you can find the source of isNumber(String value)

Description

is Number

License

Apache License

Declaration

public static boolean isNumber(String value) 

Method Source Code

//package com.java2s;
/*//w w w .  ja  v a  2 s  .co m
 * Copyright 2013 NanoTemplate Team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.regex.Pattern;

public class Main {
    private static final Pattern NUMBER_PATTERN = Pattern.compile("^[0-9]+(\\.[.0-9]+)?[BSILFDbsilfd]?$");

    public static boolean isNumber(String value) {
        return isEmpty(value) ? false : NUMBER_PATTERN.matcher(value).matches();
    }

    public static boolean isNumber(char[] value) {
        if (value == null || value.length == 0) {
            return false;
        }
        for (char ch : value) {
            if (ch != '.' && (ch <= '0' || ch >= '9')) {
                return false;
            }
        }
        return true;
    }

    public static boolean isNumber(byte[] value) {
        if (value == null || value.length == 0) {
            return false;
        }
        for (byte ch : value) {
            if (ch != '.' && (ch <= '0' || ch >= '9')) {
                return false;
            }
        }
        return true;
    }

    public static boolean isEmpty(byte[] value) {
        return value == null || value.length == 0;
    }

    public static boolean isEmpty(char[] value) {
        return value == null || value.length == 0;
    }

    public static boolean isEmpty(String value) {
        return value == null || value.length() == 0;
    }
}

Related

  1. isNumber(String str)
  2. isNumber(String str)
  3. isNumber(String str, String sign)
  4. isNumber(String value)
  5. isNumber(String value)
  6. isNumber_Lowerletter_Underline(String str)
  7. isNumberForLength(String numStr, int length)
  8. isNumberLiteral(String s)
  9. isNumberOfShownValue(String inputString)