Results 1 to 8 of 8
  1. #1
    Lovie is offline Member
    Join Date
    Apr 2009
    Location
    South Jersey
    Posts
    3
    Rep Power
    0

    Default Java Form Validation

    I created a small servlet program with a form asking for User First and Last Name, Gender then hit the Submit button. However I want to validate the form so that if the user does not enter their full name and select a gender then the program should display a message saying the the form is incomplete. I need some help on the validation coding?

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    what do you specifically need help with doing? to validate parameters, you need to get them and then compare them to whatever makes them in/valid.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Basically you need to validate fields, comparing with the database or a text file is the option you have to take.

  4. #4
    Lovie is offline Member
    Join Date
    Apr 2009
    Location
    South Jersey
    Posts
    3
    Rep Power
    0

    Default

    Its like completing a form with mandatory fields. If the user did not enter information into a field eg. last name, they should get a prompt saying, "Please enter your last name". So I need to validate 4 inputs: firstName, lastName, gender: whether Male or Female, or if user hits the Submit button without entering any data at all.

  5. #5
    Lovie is offline Member
    Join Date
    Apr 2009
    Location
    South Jersey
    Posts
    3
    Rep Power
    0

    Default

    I wanted to verify where in the program I put the validation codes and should it be another small program or class:

    if (firstName != null) {
    System.out.println("Please enter first name");
    else if (lastName != null) {
    System.out.println("Please enter last name");
    Else if (firstName == null) && (lastName == null) {
    System.out.println("Please enter your first and last name");
    etc......

    I am not 100% sure that I have the syntax correct with the != or ==

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Validation is depends on your application design.

    The way you workout is not bad. But the thing is not in standard. Say you entered a number as the first name, still it's valid. Because you just check is for null value. Same for other fields as well.

  7. #7
    dyapasrikanth is offline Member
    Join Date
    Sep 2009
    Posts
    11
    Rep Power
    0

    Default

    try to use java script
    <script>
    function x()
    {
    if(-)
    return true
    else
    return false
    }
    </script>
    <form action="/asf" method="get" onsubmit="return x()"
    ---
    </form>

  8. #8
    dyapasrikanth is offline Member
    Join Date
    Sep 2009
    Posts
    11
    Rep Power
    0

    Default

    try to use java script
    <script>
    function x()
    {
    if(-)
    return true
    else
    return false
    }
    </script>
    <form action="/asf" method="get" onsubmit="return x()">
    ---
    </form>

Similar Threads

  1. Live Email Validation In Java
    By shameel in forum Web Frameworks
    Replies: 9
    Last Post: 01-05-2010, 05:42 AM
  2. Form Validation Design
    By Algatron in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-21-2009, 10:30 PM
  3. Form validation in struts
    By rekha in forum Web Frameworks
    Replies: 2
    Last Post: 03-19-2009, 08:55 AM
  4. form validation
    By abhiN in forum New To Java
    Replies: 0
    Last Post: 03-07-2008, 07:04 AM
  5. java validation?
    By lockmac in forum New To Java
    Replies: 3
    Last Post: 08-14-2007, 04:34 PM

Posting Permissions

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