Java examples for java.lang:String Contain
Checks if a String contains a valid numeric, in this definition either 1 or more digits or 0 or more digits, followed by a dot (.), followed by 1 or more digits.
//package com.java2s; public class Main { public static void main(String[] argv) { String string = "java2s.com"; System.out.println(isNumeric(string)); }/*from w ww . j a va 2s. com*/ /** * Checks if a {@link String} contains a valid numeric, in this definition either * <ul> * <li>1 or more digits <i>or</i></li> * <li>0 or more digits, followed by a dot (.), followed by 1 or more digits. * </ul> * * @param string * The {@link String} to test. * @return {@code true} if it is a valid numeric, {@code false} otherwise. */ public static boolean isNumeric(String string) { return string.matches("([0-9]*\\.)?[0-9]+"); } }