Advertisement
tiagooleite2

Untitled

Nov 15th, 2020
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. package expressaoregular;
  2.  
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class MascaraValidacaoNumeroReal {
  7.    
  8.     public static boolean ehNumeroRealValido(String numero) {
  9.         if (numero == null || numero.trim().isEmpty()) {
  10.             return false;
  11.         }
  12.        
  13.         Pattern patternNumero1 = Pattern.compile("\\+?\\-?\\d+(\\.\\d+)?");
  14.         Matcher matcherNumero1 = patternNumero1.matcher(numero);
  15.        
  16.         Pattern patternNumero2 = Pattern.compile("\\+?\\-?\\d.+\\[.]\\d+");
  17.         Matcher matcherNumero2 = patternNumero2.matcher(numero);
  18.        
  19.         if (matcherNumero1.find() || matcherNumero2.find()) {
  20.             return true;
  21.         }
  22.        
  23.         return false;
  24.     }
  25.  
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement