🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1677

Find a good way to verify the data type.

#1677
From: qian_x_j
Date: Wed, 31 Oct 2001 13:11
26 lines
1808 bytes
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: <3bdff856_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-03!supernews.com!sjcppf01.usenetserver.com!usenetserver.com!sunqbc.risq.qc.ca!cpk-news-hub1.bbnplanet.com!lsanca1-snf1!news.gtei.net!enterprise!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,427855c64bbd2cfb,start
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2001-10-31 05:41:31 PST
From: "qian_x_j" <qian_x_j@cmmail.com>
Newsgroups: borland.public.jbuilder.java.api
Subject: Find a good way to verify the data type.
Date: Wed, 31 Oct 2001 21:11:59 +0800
Lines: 28
Organization: core
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2462.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000
NNTP-Posting-Host: 211.154.130.130
Message-ID: <3bdff856_2@dnews>
X-Trace: dnews 1004533846 211.154.130.130 (31 Oct 2001 05:10:46 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-03!supernews.com!sjcppf01.usenetserver.com!usenetserver.com!sunqbc.risq.qc.ca!cpk-news-hub1.bbnplanet.com!lsanca1-snf1!news.gtei.net!enterprise!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews