Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package expressaoregular;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class MascaraValidacaoNumeroReal {
- public static boolean ehNumeroRealValido(String numero) {
- if (numero == null || numero.trim().isEmpty()) {
- return false;
- }
- Pattern patternNumero1 = Pattern.compile("\\+?\\-?\\d+(\\.\\d+)?");
- Matcher matcherNumero1 = patternNumero1.matcher(numero);
- Pattern patternNumero2 = Pattern.compile("\\+?\\-?\\d.+\\[.]\\d+");
- Matcher matcherNumero2 = patternNumero2.matcher(numero);
- if (matcherNumero1.find() || matcherNumero2.find()) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement