For Programmers: Free Programming Magazines  


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???
DJM

2004-03-28, 10:36 pm

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!)
Joe

2004-03-28, 10:36 pm

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!)
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com