Here you can find the source of isNumeric(String value, Locale locale)
Parameter | Description |
---|---|
value | the value to check |
locale | the locale, against which the value is checked (checks locale specific decimal and grouping separators) |
public static boolean isNumeric(String value, Locale locale)
//package com.java2s; /*//ww w. ja v a 2s . c om * Copyright 2015-2016 OpenEstate.org. * * 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.text.DecimalFormatSymbols; import java.util.Locale; public class Main { /** * Test, if a string contains a parsable number. * * @param value * the value to check * * @param locale * the locale, against which the value is checked * (checks locale specific decimal and grouping separators) * * @return * true, if the provided value contains of numbers */ public static boolean isNumeric(String value, Locale locale) { if (value == null) return false; int start = 0; final DecimalFormatSymbols symbols = (locale != null) ? DecimalFormatSymbols.getInstance(locale) : DecimalFormatSymbols.getInstance(); if (value.startsWith("+") || value.startsWith("-")) start++; boolean fraction = false; for (int i = start; i < value.length(); i++) { final char c = value.charAt(i); if (c == symbols.getDecimalSeparator() && !fraction) { fraction = true; continue; } //if (c==symbols.getGroupingSeparator() && !fraction) //{ // continue; //} if (!Character.isDigit(c)) { return false; } } return true; } }