Beispiel #1
0
 /**
  * Validates a datetime value. All values matching the "date" core validation rule, and the "time"
  * one will be valid
  *
  * @param String dateTimeString
  * @param List<String> format. The possible formats to pass to the function are : dmy 05-12-2011
  *     or 05-12-11 separators can be a space, period, dash, forward slash mdy 12-05-2011 or
  *     12-05-11 separators can be a space, period, dash, forward slash ymd 2011-12-05 or 11-12-05
  *     separators can be a space, period, dash, forward slash dMy 05 December 2011 or 05 Dec 2011
  *     Mdy December 05, 2011 or Dec 05, 2011 comma is optional My December 2011 or Dec 2011 my
  *     12/2011 separators can be a space, period, dash, forward slash
  * @param String regex. This argument is optional. If a custom regular expression is used this is
  *     the only validation that will occur
  * @return boolean true when the string is a valid datetime or false when it is not
  */
 public static boolean checkDateTime(String dateString, List<String> format, String regex) {
   // variable holding the end result
   boolean valid = false;
   // Get the various parts of the dateString.
   String[] parts = dateString.split(" ");
   if (parts != null && parts.length > 1) {
     // Get the time part
     String time = parts[parts.length - 1];
     // Reconstruct the date parts
     String date = parts[0];
     for (int i = 1; i < parts.length - 2; i++) {
       date += " " + parts[i];
     }
     // pass to the validation function
     valid = Validation.checkDate(date, format, regex) && Validation.checkTime(time);
   }
   return valid;
 }
Beispiel #2
0
  /**
   * Checks IP v6 address
   *
   * @param String ipAddress
   * @param String regex
   * @return boolean true when it is valid IPv6 or false when it is not
   */
  public static boolean checkIPv6(String ipAddress, String regex) {
    // check whether a custom regular expression is given
    if (regex != null && !regex.isEmpty()) {
      return ipAddress.matches(regex);
    }

    // Lazily load the address pattern and validate the ipAddress
    Validation.populateIp();
    return ipAddress.matches(Validation.$_patterns.get("IPv6"));
  }
Beispiel #3
0
 /**
  * Checks IP address
  *
  * @param String ipAddress
  * @param String regex
  * @return boolean true when it is valid address and false when it is not valid
  */
 public static boolean checkIp(String ipAddress, String regex) {
   return Validation.checkIPv4(ipAddress, regex) || Validation.checkIPv6(ipAddress, regex);
 }