Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 11th, 2005, 01:04 AM
Authorized User
 
Join Date: May 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Struts Validation

Hi All

I have doubt in validation using struts

There is a text field "user id" in the form.
validation 1: The user id can be a email id.. if it is in email id format then it should be validated against email id validation rules.

validation 2: The user id can also be a alpha numeric value (other than email id) in that case custom validation should be done.

(If the user id in email id format then validation 1 should be performed else validation 2 should be performed)

The validation rules are working fine if any one of them is mentioned.How should i perform the validation as mentioned above

Thanks in advance
sri
__________________
Try Try Try Until You Succeed
 
Old April 14th, 2005, 07:20 AM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi sri

We have a validate(ActionMapping mapping,HttpServletRequest request) method in the form which return the ActionErrors.
just check inside the function whether it val1 or val2 and passes the values

 
Old June 20th, 2005, 11:56 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI
You can solve this problem usint the functions that you will have to use for the mailid validation


public static boolean isValidEmailID(String emailID)
{
    boolean flag = false;
    Pattern email = Pattern.compile("^[a-zA-Z]+([\\.-_]?[a-zA-Z0-9]+)*@[a-zA-Z]+([\\.-]?\\w+)*(\\.\\w{2,5})+$");

    Matcher fit = email.matcher(emailID);
    if(fit.matches())
    {
         flag= true;
    }
    else if( containsAlphaNumeric(emailID))
    {
          flag= true;
    }
    else
    {
          flag= false;
    }
    return flag;
}


    private static boolean containsAlphaNumeric(String emailID)
    {
        Pattern email = Pattern.compile("^[A-Za-z]\\w[A-Za-z0-9]+$");
        Matcher fit = email.matcher(emailID);
        return fit.matches();
    }







Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
Problem in Struts Validation meetravig Struts 0 July 24th, 2007 01:32 AM
struts actions package: "struts", other packages? ojasrege Struts 1 July 21st, 2007 06:02 AM
Help ! Struts Validation ajai_mp Struts 1 November 13th, 2006 06:55 AM
How to get upgraded from Struts 1.1 to struts 1.2. rayalujakkaraju@yahoo.com Struts 0 January 3rd, 2006 04:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.