Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4863

constraint supports user-defined flags

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Normal Normal
    • 9.6.0
    • 9.5.1.2
    • Components
    • Security Level: Jimmy

      User Story

      As an app developer, I want to use all regular expression flags that browsers support so that I can perform various validations.

      Acceptance Criteria

      <textbox constraint="/^[\p{L}\p{P}\p{Z}\p{N}\|]{1,32}$/gmu"></textbox>
      

      The flag is gmu

      Details

      When creating RegExp, we pass a fixed flag g (see code), it's better to pass the complete regular expression specified by app developers, so that the developers can utilize all regular expression features that browsers support.

      Workaround

      If you want to use the Java Pattern flags, you can try server side validation with Embedded Flag Expressions

      (?iu) means Pattern.CASE_INSENSITIVE and Pattern.UNICODE_CASE

                       <zscript><![CDATA[
      		public class MyConstraint extends SimpleConstraint implements CustomConstraint { // server side validation
      			public MyConstraint() {
      				super("no empty, /(?iu)[A-Z]{3}/");
      			}
      			
      			public void showCustomError(Component comp, WrongValueException ex) {
      				comp.getFellow("errlb").setValue(ex != null ? ex.getMessage(): "");
      			}
      		};
      		MyConstraint myc = new MyConstraint();
      		]]></zscript>
                       <hlayout>
      			<textbox constraint="${myc}"/>
      			<label id="errlb" style="color:red"/>
      		</hlayout>
      

            Leon03 Leon03
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: