I have a struts application. Several of field are freeform, allowing
the user to type whatever they want. I want to make sure that certain
characters aren't used in those fields. Invalid characters are so
basic, I'd have figured there would be a built-in way to filter them in
Validator, but I can't find a way to do it.
Basically, I want to use validator to not permit the characters < > '
and ".
I tried to do this with a mask, as follows...
<form name="myForm">
<field property="field" depends="mask">
<msg name="mask" key="errors.invalid.chars"/>
<var>
<var-name>mask</var-name>
<var-value>[^<>'"]</var-value>
</var>
</field>
</form>
This obviously errors due to the <>. I also tried [^\<\>'"] This
errors on the < saying that "The content of elements must consist of
well-formed character data or markup."
I know I could probably do this in my code and return an action message
or something, but I'd like to see if validator does this sort of check.
Seems like it would..
Any help would be appreciated.
Bodo Wippermann - 05 Oct 2005 18:13 GMT
Spivee schrieb:
...
In XML you can use < and > instead of < and >.
HTH
Spivee - 05 Oct 2005 18:52 GMT
Ah, I should have known that! Thanks for the help. That fixed my
problem. Appreciate the quick answer.
<var>
<var-name>mask</var-name>
<var-value>^[^<>'"]*$</var-value>
</var>