aspose file tools*
The moose likes Struts and the fly likes Adding more than one validation to form field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Adding more than one validation to form field" Watch "Adding more than one validation to form field" New topic
Author

Adding more than one validation to form field

shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Hi Guys

I am using the actionClass-validation.xml method to validate form inputs. I have one field which I want to valid several things, the first I have already implemented and that is if the field is empty. The other two validations I want to implement are (1) Length of string, it must be 11 chars and (2) All chars must be numbers only. Here is what I have done so far:

actionClass-validation.xml


actionClass.java
Bejoy Kaladhar
Greenhorn

Joined: Jul 09, 2008
Posts: 9
hello...just try out this piece of coe for validator xml file.I'm sure the string length validator would work fine not sure of the int validator.Give a try.



You can do the same without the short-circuit attribute also.
[ December 19, 2008: Message edited by: Bejoy KS ]

Bejoy.K.S
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Hi
The max char works perfectly fine, but the int one doesn't work at all. If I enter letters it will still work when it shouldnt. And if I submit it the action class spits out the following error:



I tried to convert the value from int to string before storing it but everytime I would submit the form the contactno field would just turn blank.
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
I have managed to fix it. I used regex instead and that did the job.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding more than one validation to form field
 
Similar Threads
Pop up error while using validation in struts2.0
Struts2 very simple validation doesn't work
Form validation not working
struts2 validation not working
struts validation