Advertisement
GeorgePashev_88

Java Regex Validation Interface

Apr 29th, 2024
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. package com.example.kontakti;
  2.  
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public interface Validation {
  7.     public static boolean Validate(String text, String expression){
  8.         final String regex = expression;//"[\\w_\\-]+@[\\w_\\.\\-]+\\.[\\w_\\-]{2,4}";
  9.         final String string = text;
  10.  
  11.         final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  12.         final Matcher matcher = pattern.matcher(string);
  13.  
  14.         while (matcher.find()) {
  15.             return true;
  16.         }
  17.         return false;
  18.  
  19.     }
  20.  
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement