Here you can find the source of isNumber(String s, boolean[] realnum)
Parameter | Description |
---|---|
s | a parameter |
realnum | a parameter |
public static boolean isNumber(String s, boolean[] realnum)
//package com.java2s; /**// w w w.j a va 2 s . c om * SqlJetUtility.java * Copyright (C) 2009-2010 TMate Software Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * For information on how to redistribute this software under * the terms of a license other than GNU General Public License * contact TMate Software at support@sqljet.com */ import java.util.regex.Pattern; public class Main { static private final Pattern NUMBER_PATTER = Pattern .compile("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?"); static private final Pattern REAL_PATTERN = Pattern.compile("[\\.eE]+"); /** * Return TRUE if z is a pure numeric string. Return FALSE and leave realnum * unchanged if the string contains any character which is not part of a * number. * * If the string is pure numeric, set realnum to TRUE if the string contains * the '.' character or an "E+000" style exponentiation suffix. Otherwise * set realnum to FALSE. Note that just becaue realnum is false does not * mean that the number can be successfully converted into an integer - it * might be too big. * * An empty string is considered non-numeric. * * @param s * @param realnum * @return */ public static boolean isNumber(String s, boolean[] realnum) { if (s == null) return false; if (!NUMBER_PATTER.matcher(s).matches()) return false; if (realnum != null && realnum.length > 0) { realnum[0] = REAL_PATTERN.matcher(s).matches(); } return true; } }