• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Validation problem please help??

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi??
i have a problem in java...and i'm not quite sure how to solve it, and was wandering if anyone would be able to help me out here...
i have started something but not sure what to do next.
Here is the problem:
Problem 1
A program accepts identification number, first name, last name, and email address of a user. It validates the data as per following specifications:
.identification number – no blanks, four numerical characters;
.first name – no blanks, all alphabetical characters;
.last name – same as for first name;
.email address–
.no blanks;
.only one ‘@’character;
,there is at least one word before ‘@’, and at least two words after ‘@’, both words(following ‘@’ joined by ‘.’, no space between the words before and after the ‘.’ character.
Assume that there are maximum of two words following ‘@’character, and there are maximum of 25 characters in the email address.
If any of the data item is invalid, program displays an appropriate message to the user and asks for re-entry of that item.
When all data items entered are valid, program creates a password for the user by joining:
.first two characters of first name;
.2nd and 3rd characters of identification
.last three characters from the last name;
in above order.
Password is then relayed back to user. Later then enters this password and program then checks that user has entered the correct password (as created for him/her), and displays the message to the user accordingly.
You do not need to create any special user interface but must utilize string and array processing functions
and here is my source code so far.. if any one helpful enough could fix the program for me that would be much appreciated..thanks
kind regards,
Atif.
/******begining of code ****************|

/*****************end of code*******************/
[I've edited your post, surrounding the code with the proper ubb tags in order to preserve formatting and make the code easier to understand. -Dirk]
[ May 21, 2002: Message edited by: Dirk Schreckmann ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
atif,
Thank you for registering with a valid JavaRanch display name.
Continuing this conversation from your previous post...
From my point of view, it would be much easier to help you figure out this problem, if we knew just a little bit about your comfort level with Java programming. Do you know how to get a single input from the user and display this input?
Have you tried my previous suggestion to "write a very simple program to just get one piece of information. Once you get that working, then try dealing with multiple attributes and the required manipulations."
Don't forget, the code you've posted won't compile. I've made note of a trouble area in a comment above.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi dirk,
yes i know how to get a single input from the user..
for example if for the ID, i have to convert it to a string first like this..
<code>
id = Integer.parseInt(input.readLine());
</code>
then, ask user to input the string:
but, the trouble im having is how to validate the input by making sure there are no blanks, and only 4 numerical characters are entered...
then, get the firstname from the user and the lastname...
<code>
something like this: System.out.println("Enter Firstname:");
firstname = input.readLine();
//then validate here and check for no blanks and only alphabetical characters entered..
and same for the lastname..
</code>
Back to you dirk...
what do you think..can you help me some how ??
kind regards
Atif.
 
atif abbas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry. dirk i was using my old login name for the previous reply..
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Atif,
Look at the String method toCharArray(). It should help you along with some Character methods. For example, no blanks:

Another example all digits:

Regards,
Manfred.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As David suggested, if you were familiar with regular expressions, then making use of the new regex package would be easiest. I haven't run across any great regex tutorials yet (nor have I looked very hard), though a decent one that explains the use of a (free) third party regex package can be found at javaregex.com.
Without the regex package, you'll just have to make liberal use of Manfred's suggestion and the various methods available in the String class.
As an example, the first entry must be four numerical characters long with no spaces. Before or after (I'd choose before) the input passes Manfred's two tests, make sure that the length of the input String ( String::length() ) is equal to four. And so on... If you're going to be doing a lot of this, then learning the regex package is definitely the way to go.
Are you getting any ideas?
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
some ideas on using the Character Class
Jamie
 
atif abbas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey, guys many thanks for your help..
but i still get errors when i compile...
i have tried what you guys sais but not working..
Also how am i able to retrieve the password, once i have got the firstname, lastname and id..
if you read my question from the project it mentions that the password is created by the joining the firstname, id and lastname..
can you guys help me here again please...
here is my code so far..

[ May 22, 2002: Message edited by: Dirk Schreckmann ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, Let's discuss some of the errors in your example. I've used caps to bring emphasis to my comments.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would seem to me that you'd do well to start smaller and then build your larger program (as I've suggested).
Write a simple program to get just a String from the user, then display the gotten String to verify you know how to get a String and use it. Can you do this?
I'd guess, that with the ackward attempts at recursion in your various methods, you were trying to keep getting input from the user until the gotten input were in the proper format. Try a while loop instead. Something along these lines:

Good Luck.
 
no wonder he is so sad, he hasn't seen this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic