开发者

Struts Regex Validation

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 esc开发者_如何转开发aped but I am unable to find any specific rules of regex in struts.


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.


This might help you

<constant>
      <!--All characters except < > " ' & % ; | and ~-->
      <constant-name>allchars</constant-name>
      <constant-value>^[^&lt;&gt;&quot;&apos;&amp;%;|~]*$</constant-value>
 </constant>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜