Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Validation Methods

hi,

i need some help in implementing validation to my program;

the program prompts the user to enter the details and error message is displayed if a wrong input is entered. The user is then prompted to enter the correct information again. I just need some help with 3 validation methods;

//able to enter only alphabets and / only
System.out.print("Enter user name: " );
user.name = input.readLine();

While{}

//must be ONLY 'A' or 'B'
System.out.print("Enter user prefix (A/B): ");
String prf = input.readLine();
user.prefix= prf.charAt(0);

While{}

//able to enter only alpha-numeric
System.out.print("Enter user address: ");
user.address = input.readLine();

While{}

Really appreciate of someone could help me with the conditions for this validation process..

Thanks!!
[934 byte] By [Jess_00] at [2007-11-11 8:26:34]
# 1 Re: Validation Methods
What attribute are you testing for in each of your while loops - what is being "A or B", or "alphabetic", or "alphanumeric"? How do you test for that/those value(s)? Are there existing methods which will perform that testing for you? Do you need to write your own?
nspils at 2007-11-11 22:35:20 >
# 2 Re: Validation Methods
hi,

thanks for the reply. i have highlighted the conditions in RED.
"A" or "B" are the ONLY two inputs which should be accepted by the program. another other alphabets or numerics entered will prompt an error message and the user will prompted to re-enter the correct value again.

There are no other existing testing methods and these are the only validation methods to be used for this program.

thanks.
Jess_00 at 2007-11-11 22:36:26 >
# 3 Re: Validation Methods
I was trying to prompt your research into the methods available to you for your use in crafting the tests you need. Primarily, I was prompting you to search the J2SE API methods which you can find to use to test the input.

There are String class methods which will do what you need. What are they? Are there class methods to test isAlphaNumeric()? Can you test an ascii value, or equals() a particular character?
nspils at 2007-11-11 22:37:24 >