title: Using Regular Expressions in Generic Methods in Java
body: <p>Hi am new to using regular expression as generic methods in java.I am confusing with How to use Regular Expression as generic methods in Java.
  Generally Regular expression will take String type but i need a requirement for it will accept all datatypes like <code>int</code>, <code>double</code>, <code>float</code>.....
  Below is my code it returns <code>true</code> or <code>false</code> value based on regular expression and Given data.
  But my question is here it valid only for <code>String</code> values.I need it on Int format(like Generic methods).</p>
  
  <pre><code>import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  
  public class StringValidator {
  public boolean stringMultiFormat(String str, String regex) {
      boolean isValid = false;
      CharSequence inputStr = str;
      // Make the comparison case-insensitive.
      Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
      Matcher matcher = pattern.matcher(inputStr);
  
      if (matcher.matches()) {
          isValid = true;
          System.out.println(isValid);
      } else {
          System.out.println(isValid);
      }
      return isValid;
  }
  
  public static void main(String[] args) {
      StringValidator aiov = new StringValidator();
  
      String num = "^\\s*(?:\\+?(\\d{1,3}))?([-. (]*(\\d{3})[-. )]*)?((\\d{3})[-. ]*(\\d{2,4})(?:[-.x ]*(\\d+))?)\\s*$";
  
      if (aiov.stringMultiFormat("(650)-055-2345", num)) {
          System.out.println("Given number is Valid Mobile Number");
      } else {
          System.out.println("Given number is Invalid Mobile Number");
      }
  
  }
  }
  </code></pre>
  
  <p>Thanks in Advance!</p>