Class Valid

java.lang.Object
fc.web.simpleforms.Valid

public final class Valid extends Object
Utility methods for common validation needs.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isAllowed(String str, String allowedChars)
    Returns true if the specified string only contains the allowed characters.
    static boolean
     
    static boolean
    Ensures that the string is composed of only floating point numbers (digits [0-9] and maybe a "."), with optional leading/trailing blanks.
    static boolean
    Ensures that the string is composed of only an digits [0-9] with optional leading/trailing blanks.
    static boolean
    isNotAllowed(String str, String unallowedChars)
    Returns true if the specified string has no unallowed characters.
    static boolean
    Returns true is the specified string is not null and not empty ("").
    static boolean
    length(String str, int min, int max)
    Returns true if the string is non-empty and it's length is between the specified min and max lengths (both inclusive).
    static void
    main(String[] args)
     
    static void
    setTrimSpaces(boolean val)
    If set to true, methods in this class will trim the string entered by the user before attempting to run further validation on it, else strings will not be trimmed automatically.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • setTrimSpaces

      public static void setTrimSpaces(boolean val)
      If set to true, methods in this class will trim the string entered by the user before attempting to run further validation on it, else strings will not be trimmed automatically. Defaults to true.
    • isIntegerOnly

      public static boolean isIntegerOnly(String str)
      Ensures that the string is composed of only an digits [0-9] with optional leading/trailing blanks. (floating point/real numbers are not allowed because they contain a ".")
    • isFloatOnly

      public static boolean isFloatOnly(String str)
      Ensures that the string is composed of only floating point numbers (digits [0-9] and maybe a "."), with optional leading/trailing blanks. Negative numbers (with a leading "-") are also allowed.
    • isEmpty

      public static boolean isEmpty(String str)
    • isNotEmpty

      public static boolean isNotEmpty(String str)
      Returns true is the specified string is not null and not empty ("").
    • length

      public static boolean length(String str, int min, int max)
      Returns true if the string is non-empty and it's length is between the specified min and max lengths (both inclusive).
    • isAllowed

      public static boolean isAllowed(String str, String allowedChars)
      Returns true if the specified string only contains the allowed characters. If the string contains any other characters that are not allowed, returns false
    • isNotAllowed

      public static boolean isNotAllowed(String str, String unallowedChars)
      Returns true if the specified string has no unallowed characters. If the string contains any unallowed characters, returns false
    • main

      public static void main(String[] args)