www.webdeveloper.com
Results 1 to 3 of 3

Thread: page validation

  1. #1
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898

    page validation

    We have startded coding a new jsf web application. We have a login page that has a userid and password field. We have a PageValidationController class that we are going to use for page validation for our application to validate userid/password/emails, etc. Could someone help me write the code to validate the userid and password the user enters? This is just page validation, so we want to validate things like, the user id cannot start with _*+/, etc, Must be at least 6 characters long. The same with the password. I am new to java.

    Thanks

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    You could pick all this stuff up from a basic Java tutorial.
    Code:
    String strUser = // where ever you get your username from.
    String strIllegal = "_, /, *, +, -, %, @, $";
    if (strIllegal.indexOf(strUser.substring(0, 1)) > -1)
       // Starts with an illegal character.
    Regards.

  3. #3
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    could you show me how to put this in a class called PageDataValidation?

    I have this, but am getting errors (in bold below):

    [code]
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import javax.faces.FactoryFinder;
    import javax.faces.application.Application;
    import javax.faces.application.ApplicationFactory;
    import javax.faces.application.Message;
    import javax.faces.component.UIComponent;
    import javax.faces.component.UIOutput;
    import javax.faces.context.FacesContext;
    import javax.faces.context.MessageResources;
    import javax.faces.validator.Validator;



    /**
    * @author PRGJXY
    *
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    */
    public abstract class PageDataValidator implements Validator {

    public void validateUserId(userId) {
    String strIllegal = "_, /, *, +, -, %, @, $";
    if (userID == null || userID == "" || userID.length() == 0) {

    } else if (strIllegal.indexOf(userId.substring(0,1)) > -1) {

    }

    }
    public void validatePassword(password) {

    if (password == null || password == "" || password.length() == 0) {

    } else if (password.length() < 6 || password.length() > 15) {

    }
    }

    }

    [/code/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles