Home > Archive > Java Help > March 2004 > Input Validation???
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Input Validation???
|
|
|
| How do I make sure that the data which a user inputs is actually
valid?
e.g.
I have a String called userID of the type ID000001. How do I make sure
that what is input is of that format/length? (i.e. not ID01)
I have a float called cost. How do I make sure that what is input is
actually what I want?
How do I validate a date, so that it is of the format dd/mm/yy?
(I have probably not explained what I am wanting to know too well;
sorry!)
| |
|
| In article <3f991599.0403280347.4aae4a31@posting.google.com>, DJM_666
@msn.com says...
> How do I make sure that the data which a user inputs is actually
> valid?
>
> e.g.
There are a number of ways. You can do some simple compares, i.e.
if (null == userId || userID.length() != 8 || !userID.startsWith("ID"))
{
// show error message
}
or, for your float yuo can do Float m_cost = new Float(cost) and
catch a NumberFormatException to show an error message to the user
> I have a String called userID of the type ID000001. How do I make sure
> that what is input is of that format/length? (i.e. not ID01)
> I have a float called cost. How do I make sure that what is input is
> actually what I want?
> How do I validate a date, so that it is of the format dd/mm/yy?
>
>
> (I have probably not explained what I am wanting to know too well;
> sorry!)
>
|
|
|
|
|