Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Validator - check for invalid characters?

Thread view: 
Spivee - 05 Oct 2005 18:03 GMT
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 &lt; and &gt; 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>^[^&lt;&gt;'"]*$</var-value>
       </var>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.