Created
December 13, 2017 22:30
-
-
Save gabrielstelmach/7a80d213d2bd3dfde89575022782eec4 to your computer and use it in GitHub Desktop.
Simple method to evaluate numeric values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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