Article View: borland.public.jbuilder.java.api
Article #1680Re: Find a good way to verify the data type.
From: John Baker
Date: Thu, 01 Nov 2001 11:01
Date: Thu, 01 Nov 2001 11:01
35 lines
2091 bytes
2091 bytes
Use of one of the regular expression APIs to build some kind of generic
verifier would be something I would look into..
qian_x_j <qian_x_j@cmmail.com> wrote in message news:3bdff856_2@dnews...
> Who can tell me a good way to verify the data type of a "String" can be
e.g.
> integer, date in java?
>
> Here's my way to verify the long data:
> try{
> java.text.Long.parseLong(anString);
> }catch(Exception ex){
> setFalse();
> }
> And here's my way to verify the date data:
> java.text.DateFormat df =new
java.text.SimpleDateFormat("yyyy-MM-dd");
> df.setLenient(false);
> try{
> df.parse(anDateString);
> }catch(Exception ex){
> setFalse();
> }
> The codes looks ugly. And there is another problem: It can identify
> "2001-2-hree5" not parse to date, but it look "2001-3-3fjaflej" as a
correct
> date formate! So I must add the code ahead:
> if(Character.isDigit(anDateString.charAt(anDateString.length()-1)) ==
> false){
> setFalse();
> }
>
> Any one can tell me the elegant way to do this?
>
>
Technical Details
Message-ID:
<3be128ba_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!feed2.news.rcn.net!rcn!newsfeed1.earthlink.net!newsfeed2.earthlink.net!newsfeed.earthlink.net!lsanca1-snf1!news.gtei.net!enterprise!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3bdff856_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,427855c64bbd2cfb X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-11-01 03:00:51 PST From: "John Baker" <jbaker@SoftComms.com> Newsgroups: borland.public.jbuilder.java.api References: <3bdff856_2@dnews> Subject: Re: Find a good way to verify the data type. Date: Thu, 1 Nov 2001 11:01:22 -0000 Lines: 37 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 NNTP-Posting-Host: 217.134.212.135 Message-ID: <3be128ba_2@dnews> X-Trace: dnews 1004611770 217.134.212.135 (1 Nov 2001 02:49:30 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!feed2.news.rcn.net!rcn!newsfeed1.earthlink.net!newsfeed2.earthlink.net!newsfeed.earthlink.net!lsanca1-snf1!news.gtei.net!enterprise!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews