*
The moose likes Struts and the fly likes Email validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Email validation" Watch "Email validation" New topic
Author

Email validation

charu latha
Ranch Hand

Joined: Aug 20, 2002
Posts: 67
I have a jsp page in which i get an email id from the user. I have taken the validation from struts itself.

My jsp page is like this:

<td width="25%"><b><html:text property="emailID" /></b></td>

I have written in my validator.xml the follwing lines:

<field property="emailID" depends="required,email">
<arg0 key="registerForm.emailid" />
</field>

I know i have to check the email in my form bean but i am unable to decipher how. Its something basic i know but i am really stumped how.

My validation for required in the form bean i have written as shown below:

if (getEmailID() == null || getEmailID().length() < 1){
System.out.println ("if loop emailid name is " + emailID);
errors.add("emailID", new ActionError("errors.registerForm.emailid.required"));
}

Now for the email validation how should i do it in the form bean. Am i thinking about this the wrong way?

Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
If you're using the validator plugin, you shouldn't need to code anything into your FormBean -- the 'email' validation is built-in into the framework.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Marc Winder
Greenhorn

Joined: Nov 26, 2003
Posts: 6
Lasse is right but check your validator-rules.xml and make sure it includes the email validator definition which should include the "validateEmail" JS function. If so, you should be all set.
charu latha
Ranch Hand

Joined: Aug 20, 2002
Posts: 67
Ok i checked my validator rules and it has the function but for some reason my email never gets checked. any ideas?

Prasanna Puttappa
Ranch Hand

Joined: Jul 21, 2003
Posts: 54
1. Is your form bean extending org.apache.struts.validator.ValidatorForm ?
2. Is property name same in your xml file and formbean class ??

- Prasanna


~Prasanna (SCJP5.0, SCWCD5)
charu latha
Ranch Hand

Joined: Aug 20, 2002
Posts: 67
hi,

thanks for your post. nope my bean extends actionform and not validatorform.

 
Don't get me started about those stupid light bulbs.
 
subject: Email validation
 
Similar Threads
How to display error message
Struts 1.2 retaininf form fields in jsp in validation error
Struts validator question
Multipage form validation
how to do validation in struts1