Here you can find the source of isNumeric(String s)
Parameter | Description |
---|---|
s | String |
public static boolean isNumeric(String s)
//package com.java2s; //License from project: Apache License import java.util.regex.Matcher; import java.util.regex.Pattern; import static java.util.regex.Pattern.compile; public class Main { private final static Pattern DIGIT_REGEX = compile("\\p{Digit}+"); /**/*from w w w. j ava2 s . c om*/ * Returns {@code true} if {@link String s} is numeric (i.e., the * {@code Digit} POSIX character class) characters and nothing else. * * @param s {@link String} * @return boolean */ public static boolean isNumeric(String s) { if (!hasLength(s)) { return false; } Matcher m = DIGIT_REGEX.matcher(s); return m.matches(); } /** * Returns {@code true} if the string is non-null and non-empty, * {@code false} otherwise. * * @param s String, may be null * @return boolean */ public static boolean hasLength(final String s) { return s != null && !s.isEmpty(); } }