Server side Integer fields validation in Struts 1.1
Amit Indore
Ranch Hand
Joined: Jun 20, 2008
Posts: 30
posted
0
Hi All, This is my first Project in Struts.
I am fessing a problem. I do not know how can i give server side validation on integer fields like Pin code/Zip , Mobile No. should be digit and specify the length.
Hi, you can use a validation frame work, or you can validate it in the 'validate' method of the Actionform. For your senario the validation in the ActionForm can be as simple as checking if the input is not empty/ if its a number/ if its of specific legenth. [ June 23, 2008: Message edited by: John Robert ]
Amit Indore
Ranch Hand
Joined: Jun 20, 2008
Posts: 30
posted
0
Originally posted by John Robert: Hi, you can use a validation frame work, or you can validate it in the 'validate' method of the Actionform. For your senario the validation in the ActionForm can be as simple as checking if the input is not empty/ if its a number/ if its of specific legenth.
[ June 23, 2008: Message edited by: John Robert ]
Yes i know but i do not want to define it's required fields and how can check whole value of variable is number And how can get length of int variable and How can define it's length.
Amit Indore
Ranch Hand
Joined: Jun 20, 2008
Posts: 30
posted
0
Originally posted by Sagar Rohankar: HI Amit ,
welcome to javaranch , This validation you can perform on client side also !
the simple search gives me thousands of example cliclk
Tahk's Sir,
I know but my sir want to server side validation.He does not want to use script.
sir, can i use server side and client side validation together.means in same jsp page.
sir, can i use server side and client side validation together.means in same jsp page
There is no good reason using both the type of validation in same JSP page,, and one major difference is server side validation is done by java classes which resides on your server and client side validation you can perform on client side like, in JSP/HTML page using scripts !!
So based on you requirement , you either choose server side or client side validation.
Now if your action form bean is extends ActionForm , then you can override validate() method and perform validation on form field like ,pincode , telephone nos, and return specific ActionError ,(See API for details)..
Or post your action form bean code here ! [ July 01, 2008: Message edited by: Sagar Rohankar ]
Amit Indore
Ranch Hand
Joined: Jun 20, 2008
Posts: 30
posted
0
Originally posted by Sagar Rohankar:
There is no good reason using both the type of validation in same JSP page,, and one major difference is server side validation is done by java classes which resides on your server and client side validation you can perform on client side like, in JSP/HTML page using scripts !!
So based on you requirement , you either choose server side or client side validation.
Now if your action form bean is extends ActionForm , then you can override validate() method and perform validation on form field like ,pincode , telephone nos, and return specific ActionError ,(See API for details)..
Or post your action form bean code here !
[ July 01, 2008: Message edited by: Sagar Rohankar ]
Hello Sir, I have done it.
I am sending my code,so please check it and suggest me that is right way or not. 1)
I put that code in Form Been Error Validation method. if(!(pincode ==null || pincode.length()<1)) { System.out.println("pincode:"+pincode); if(pincode.length()!=6)
errors.add("pincode", new ActionError("error.invalid.pincode")); }