Skip to content

Instantly share code, notes, and snippets.

@gabrielstelmach
Created December 13, 2017 22:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gabrielstelmach/7a80d213d2bd3dfde89575022782eec4 to your computer and use it in GitHub Desktop.
Simple method to evaluate numeric values
/**
* Identify a numeric value.
*
* @param value Value to be evaluated.
* @param digits May use digits or not.
* @return True when the value is a numeric representation.
*/
public static boolean isNumeric(String value, boolean digits)
{
String unmarked = value;
if ((unmarked == null) || (unmarked.trim().length() == 0))
{
return false;
}
else
{
if (digits)
{
unmarked = unmarked.replaceAll(Pattern.quote("."), "").replaceAll(",", "").replaceAll("-", "").replaceAll(" ", "");
}
return (unmarked.replaceAll("\\d+", "").length() == 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment