Annotation Type Regex


@Retention(CLASS) @Target(FIELD) public @interface Regex

Requires the component value to match a regular expression. The processor emits a com.codename1.ui.validation.RegexConstraint(pattern, message) into the Validator returned by Binding#getValidator().

@Bind(name="phoneField")
@Regex(pattern="^[0-9+\\-]+$", message="Digits, plus and dash only")
private String phone;

Use @Email or @Url for the two most common patterns -- they reuse the expressions already vetted in RegexConstraint.validEmail() / validURL().

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The regular expression.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Override the default error message.
  • Element Details

    • pattern

      String pattern
      The regular expression. Same dialect as com.codename1.util.regex.RE (a Codename One subset of standard regex that works on every supported runtime).
    • message

      String message
      Override the default error message. Required because RegexConstraint has no canned message for arbitrary patterns.
      Default:
      "Invalid value"