开发者

Struts Validation - Combining requiredif and mask

开发者 https://www.devze.com 2023-04-09 15:36 出处:网络
I have a requirement in my app where a field is required on certain conditions and then that field should match a particular pattern.

I have a requirement in my app where a field is required on certain conditions and then that field should match a particular pattern. Is there a way I can combine the requiredif and mask conditions? I am on struts 1.

Here's the validation.xml

<form-validation>
  <global>
    <constant>
      <constant-name>char</constant-name>
      <constant-name>^[a-zA-Z]*$</constant-name>
    </constant>
  </global>

  <formset>
    <开发者_StackOverflow中文版;form name="myform">
      <field property="city" depends="requiredif">
        <arg0 key="city"/>
        <var>
          <var-name>field[0]</var-name>
          <var-value>state</var-value>
        </var>
        <var>
          <var-name>fieldTest[0]</var-name>
          <var-value>EQUAL</var-value>
        </var>
        <var>
          <var-name>fieldValue[0]</var-name>
          <var-value>SEATTLE</var-value>
        </var>
      </field>
    </form>
  </formset>
</form-validation>

How do I add a mask condition so that it is checked only if the above condition is true?

Thanks

Sahil


IMO, don't; leave complex validations to Java code. The overhead of maintaining complex validations in the XML file isn't worth the effort.

"requiredif" was deprecated and should be replaced with "validwhen", btw. You can create (relatively) complex validations with "validwhen", but... ew. Much cleaner to do in Java.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号