Results 1 to 8 of 8
Thread: Java Form Validation
- 04-13-2009, 10:25 PM #1
Member
- Join Date
- Apr 2009
- Location
- South Jersey
- Posts
- 3
- Rep Power
- 0
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?
- 04-13-2009, 11:38 PM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
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.
- 04-14-2009, 04:46 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Basically you need to validate fields, comparing with the database or a text file is the option you have to take.
- 04-16-2009, 11:06 PM #4
Member
- Join Date
- Apr 2009
- Location
- South Jersey
- Posts
- 3
- Rep Power
- 0
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.
- 04-17-2009, 12:48 AM #5
Member
- Join Date
- Apr 2009
- Location
- South Jersey
- Posts
- 3
- Rep Power
- 0
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 ==
- 04-17-2009, 04:53 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 09-22-2009, 05:52 PM #7
Member
- Join Date
- Sep 2009
- Posts
- 11
- Rep Power
- 0
try to use java script
<script>
function x()
{
if(-)
return true
else
return false
}
</script>
<form action="/asf" method="get" onsubmit="return x()"
---
</form>
- 09-22-2009, 05:52 PM #8
Member
- Join Date
- Sep 2009
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Live Email Validation In Java
By shameel in forum Web FrameworksReplies: 9Last Post: 01-05-2010, 05:42 AM -
Form Validation Design
By Algatron in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-21-2009, 10:30 PM -
Form validation in struts
By rekha in forum Web FrameworksReplies: 2Last Post: 03-19-2009, 08:55 AM -
form validation
By abhiN in forum New To JavaReplies: 0Last Post: 03-07-2008, 07:04 AM -
java validation?
By lockmac in forum New To JavaReplies: 3Last Post: 08-14-2007, 04:34 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks