Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Email validation

 
charu latha
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marc Winder
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Is your form bean extending org.apache.struts.validator.ValidatorForm ?
2. Is property name same in your xml file and formbean class ??

- Prasanna
 
charu latha
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic