Solved

Struts <field-validator> for email

Posted on 2010-09-23
5
380 Views
Last Modified: 2013-11-13
Hello,

I have attached 2 validators to validate wether the user enters or leaves the email field blank and also a validator to see if is valid or not valid from the default.xml from opensymphony.

How do I add an other validator to tell me that the email already exists?  Note: im already making a DB call and already know that the email exists... Just need the actual 3rd validator.  

Please help!!!

<field name="newCompanyAdminEmail">
        <field-validator type="requiredstring">
            <message>Please enter the admin email.</message>
        </field-validator>
        <field-validator type="email">
            <message>The email address you entered is not valid.</message>
        </field-validator>
    </field>

Open in new window

0
Comment
Question by:Squadless
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33751233
<<How do I add an other validator to tell me that the email already exists?>>
but why would you want to do it, since first validator is doing exactly the same.

may be i didn't understood the requirement, can you help?
0
 
LVL 1

Author Comment

by:Squadless
ID: 33754332
sure, the first validator checks to see if the field is blank or not, the second validator checks to see if it has a @ and a . , the third validator will check to see if the email entered by the user already exists in the database.  im making the java call and know if it exists or not, but i need to catch that action using a validator not a javascript popup.
0
 
LVL 1

Author Comment

by:Squadless
ID: 33774317
HELP
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 300 total points
ID: 33775888
<<the third validator will check to see if the email entered by the user already exists in the database>>
for this, won't you need to make a server side request and then check for its existence? I dont think this is in the scope of struts validator.

i would suggest that you make an ajax request to check for its existence, so that user can continue to fill other fields
0
 

Assisted Solution

by:moj123456
moj123456 earned 200 total points
ID: 34109935
Depends what kind of 'validation' you want.

If you want to do client-side validation, you have no choice but Ajax.

If you want to do server-side validation, then the user will have to submit the form and consequently you can use code to validate it.

You cannot do client-side validation with simple javascript due to the fact that the userlist is lying in the DB (which the client, being a web browser on another computer, does not have access to).
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now