开发者

Struts Regex Validation

开发者 https://www.devze.com 2023-01-08 02:01 出处:网络
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 sp

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

精彩评论

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