Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-25-2008, 06:34 AM
Member
 
Join Date: Jul 2008
Location: CA
Posts: 15
obdi is on a distinguished road
Need Help On Entry Validation
Project is to make a data entry program, with FirstName, MiddleInitial, LastName, and SSN. Then it comes down to the entry validation part.

I think the codes i wrote are correct, tested on single entry worked great. But when i put 4 validations together(FirstName, MiddleInitial, LastName, and SSN), there is always some problems.

I only know if, else if and switch(I tried swtich but it totally didn't work for me), this code was my last try on else if, and this way of coding always ends up poping the alpha - numeric entry error msg, for the FirstName entry. And I'm totally out of ideas of how to write the validation code. Please help!

part of the code
Code:
//Validating First Name Filed if(TOne.getText().length() != 0 && Determinator == BufferOne.length()) { for(k = 0; k < BufferOne.length(); k++) { for(m = 0; m < 26; m++) { if(BufferOne.charAt(k) == Alpha.charAt(m)) { Determinator++; } } } } else if(TOne.getText().length() == 0) { JOptionPane.showMessageDialog(null, "First Name Field REQUIRED!"); TOne.requestFocus(); } else if(Determinator != BufferOne.length()) { JOptionPane.showMessageDialog(null, "INVALID CHARACTER at First Name Field!" + "\nPlease Enter A Valid FIRST NAME!"+ "\nEntry Should be Alpha Character A-Z!"); TOne.setText(""); TOne.requestFocus(); }
Code with The Action()
Code:
private class ClickWrite implements ActionListener { public void actionPerformed(ActionEvent e) { String MeUp, BufferOne, BufferTwo, BufferThree, BufferFour; String Alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String Numeric = "0123456789"; int k,m,Determinator; try { FileWriter WriteStream = new FileWriter("c:/random/IOFile.txt",true); PrintWriter Write = new PrintWriter(WriteStream); BufferOne = TOne.getText().toUpperCase(); BufferTwo = TTwo.getText().toUpperCase(); BufferThree = TThree.getText().toUpperCase(); BufferFour = TFour.getText(); Determinator = 0; //Validating First Name Filed if(TOne.getText().length() != 0 && Determinator == BufferOne.length()) { for(k = 0; k < BufferOne.length(); k++) { for(m = 0; m < 26; m++) { if(BufferOne.charAt(k) == Alpha.charAt(m)) { Determinator++; } } } } else if(TOne.getText().length() == 0) { JOptionPane.showMessageDialog(null, "First Name Field REQUIRED!"); TOne.requestFocus(); } else if(Determinator != BufferOne.length()) { JOptionPane.showMessageDialog(null, "INVALID CHARACTER at First Name Field!" + "\nPlease Enter A Valid FIRST NAME!"+ "\nEntry Should be Alpha Character A-Z!"); TOne.setText(""); TOne.requestFocus(); } //Validating Middle Initial Field else if(TTwo.getText().length() != 0 && Determinator == BufferTwo.length()) { for(k = 0; k < BufferTwo.length(); k++) { for(m = 0; m < 26; m++) { if(BufferTwo.charAt(k) == Alpha.charAt(m)) { Determinator++; } } } } else if(TTwo.getText().length() == 0) { JOptionPane.showMessageDialog(null, "Middle Initial Field REQUIRED!"); TTwo.requestFocus(); } else if(Determinator != BufferTwo.length() || Determinator > 1) { JOptionPane.showMessageDialog(null, "INVALID CHARACTER at Middle Initial Field!" + "\nPlease Enter A Valid MIDDLE INITIAL!"+ "\nEntry Should be Alpha Character A-Z!"); TTwo.setText(""); TTwo.requestFocus(); } //Validating Last Name Field else if(TThree.getText().length() != 0 && Determinator == BufferThree.length()) { for(k = 0; k < BufferThree.length(); k++) { for(m = 0; m < 26; m++) { if(BufferThree.charAt(k) == Alpha.charAt(m)) { Determinator++; } } } } else if(TThree.getText().length() == 0) { JOptionPane.showMessageDialog(null, "Last Name Field REQUIRED!"); TThree.requestFocus(); } else if(Determinator != BufferThree.length()) { JOptionPane.showMessageDialog(null, "INVALID CHARACTER at Last Name Field!" + "\nPlease Enter A Valid LAST NAME!"+ "\nEntry Should be Alpha Character A-Z!"); TThree.setText(""); TThree.requestFocus(); } //Validating SSN Field else if(TFour.getText().length() != 0 && Determinator == BufferFour.length()) { for(k = 0; k < BufferFour.length(); k++) { for(m = 0; m < 10; m++) { if(BufferFour.charAt(k) == Numeric.charAt(m)) { Determinator++; } } } } else if(TFour.getText().length() == 0) { JOptionPane.showMessageDialog(null, "SSN Field REQUIRED!"); TFour.requestFocus(); } else if(Determinator != BufferFour.length()) { JOptionPane.showMessageDialog(null, "INVALID CHARACTER at SSN Field!" + "\nPlease Enter A Valid SSN!"+ "\nEntry Should be Numeric Numbers 0-9!"); TFour.setText(""); TFour.requestFocus(); } else { BufferThree = ""; BufferThree = TThree.getText().toLowerCase() + " "; BufferThree = BufferThree.substring(0,20); BufferThree = BufferThree.substring(0,1).toUpperCase() + BufferThree.substring(1,20); MeUp = BufferThree; BufferOne = ""; BufferOne = TOne.getText().toLowerCase() + " "; BufferOne = BufferOne.substring(0,15); BufferOne = BufferOne.substring(0,1).toUpperCase() + BufferOne.substring(1,15); MeUp = MeUp + BufferOne; BufferTwo = ""; BufferTwo = TTwo.getText().toUpperCase() + " "; BufferTwo = BufferTwo.substring(0,1); MeUp = MeUp + BufferTwo; BufferFour = ""; BufferFour = TFour.getText() + " "; BufferFour = BufferFour.substring(0,9); MeUp = MeUp + BufferFour; Write.println(MeUp); JOptionPane.showMessageDialog(null, "Record is written, c:/random/IOFile.txt"); WriteRecord.setEnabled(true); AddRecord.setEnabled(true); } Write.close(); } catch(IOException WhatIsTheMatter) { System.out.println("IO Error = " + WhatIsTheMatter.getMessage()); } } }
If i create different Buttons that would work, like FirstName Button LastName Button i.e.
But i'm wondering how do i do it in one button? and how can i write all of them under one action(), Thanks!!

Last edited by obdi : 07-25-2008 at 06:45 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-25-2008, 06:44 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Why don't you use nested if loops there. It's simple.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-25-2008, 08:11 AM
Member
 
Join Date: Jul 2008
Location: CA
Posts: 15
obdi is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Why don't you use nested if loops there. It's simple.
Code:
if(TOne.getText().length() == 0) { JOptionPane.showMessageDialog(null, "First Name Field REQUIRED!"); TOne.requestFocus(); } else if(Determinator != BufferOne.length()) { JOptionPane.showMessageDialog(null, "INVALID CHARACTER at First Name Field!" + "\nPlease Enter A Valid FIRST NAME!"+ "\nEntry Should be Alpha Character A-Z!"); TOne.setText(""); TOne.requestFocus(); } else if(Determinator == BufferOne.length() && TOne.getText().length() != 0) { for(k = 0; k < BufferOne.length(); k++) { for(m = 0; m < 26; m++) { if(BufferOne.charAt(k) == Alpha.charAt(m)) { Determinator++; } } } } else if() else if() ...
still having the same problem, keep displaying alpha - numeric error msg, or is it i'm not placing the codes right?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-25-2008, 08:39 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
No obdi, I;m talking about nested if statements.

Code:
if() { if() { if() { ...... } } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
An address book, using a wizard to add a new entry Java Tip SWT 0 07-02-2008 10:11 PM
How to prevent duplicate username entry in database? anki1234 JavaServer Pages (JSP) and JSTL 4 01-09-2008 10:02 AM
Duplicate entry in registration form!!! anki1234 Advanced Java 1 01-04-2008 10:15 PM
need help checking monthlyRate entry lowpro New To Java 1 11-17-2007 07:15 AM
javascript validation yuchuang New To Java 5 05-14-2007 05:38 PM


All times are GMT +3. The time now is 12:27 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org