🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7577

Re: check a string format

#7577
From: Vladimir Stefanovic
Date: Thu, 20 Jan 2005 18:37
57 lines
2121 bytes
I do not know if there is some standard, ready to use
function for that, but you can easily make your own
version. This version assumes checks for HH:mm.

bool IsHourMinute( AnsiString AText )
{

   if ( AText .Length() != 5 )
      return ( false );

   if ( AText [3] != ':' )
      return ( false );

   int H, M;

   if ( AText [1] < '0' || AText [1] > '9' )
      return ( false );

   if ( AText [2] < '0' || AText [2] > '9' )
      return ( false );

   if ( AText [4] < '0' || AText [4] > '9' )
      return ( false );

   if ( AText [5] < '0' || AText [5] > '9' )
      return ( false );

   try
   {
      H = ( AText [1] - '0' ) * 10 + AText [2] - '0';
      M = ( AText [4] - '0' ) * 10 + AText [5] - '0';
   }
   catch ( const Exception& )
   {
      return ( false );
   }

   if ( H < 0 || H > 23 )
      return ( false );

   if ( M < 0 || M > 59 )
      return ( false );

   return ( true );
}


-- 
Best regards,
Vladimir Stefanovic
"DaniD" <together24@yahoo.com> wrote in message 
news:41efeefa@newsgroups.borland.com...
>
>  Hello,
> How can I check if a String has a format such as "hh:mm"?
> I want to be able to check if the inserted time is right.
> Thanks, 
Technical Details
Message-ID: <41effa78$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41efeefa@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,75a5742ba1befd01
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Vladimir Stefanovic" <antivari@po.sbb.co.yu>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41efeefa@newsgroups.borland.com>
Subject: Re: check a string format
Date: Thu, 20 Jan 2005 19:37:57 +0100
Lines: 59
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 82.117.212.65
Message-ID: <41effa78$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1106246264 82.117.212.65 (20 Jan 2005 10:37:44 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail