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>^[^<>"'&%;|~]*$</constant-value>
</constant>
精彩评论