2

I am using struts 1.2. I need to design a validation that reject characters %,/,?,<,>. As you can identify last two characters need to be escaped but I am unable to find any specific rules of regex in struts.

Muhammad Imran Tariq
  • 22,654
  • 47
  • 125
  • 190
rahul jain
  • 23
  • 5
  • You need to use the "mask" validator with the suitable regex pattern. If your query is on help with the actual regex, then change your title and tags to include regex, you'll get a better response. – JoseK Jul 19 '10 at 09:47

2 Answers2

0

This might help you

<constant>
      <!--All characters except < > " ' & % ; | and ~-->
      <constant-name>allchars</constant-name>
      <constant-value>^[^&lt;&gt;&quot;&apos;&amp;%;|~]*$</constant-value>
 </constant>
JAB
  • 3,546
  • 9
  • 36
  • 39
0
String str; //the string to check - load it up with the value from the form
....

if(str.contains("%") || str.contains("/") || str.contains("?") || str.contains("<") || str.contains(">")){
  //string contains invalid chars
}else{
  //string contains vaild chars
}

No regex involved, and no need to escape chars :) - although there may be better ways of doing it.

Mark W
  • 5,824
  • 15
  • 59
  • 97