?
Solved

Validate time / date with regular expression

Posted on 2007-10-18
6
Medium Priority
?
1,442 Views
Last Modified: 2013-11-26
Hi

I must convert NMEA UTC time and date to VB.NET DateTime variable.

I want validate NMEA Time (for example "182635.000" = 6:26:35 PM / 18:26:35; 000 are milliseconds that i don't use in my time variable but i want use to validation) with regular expression, but It's to difficult. Can anyone help me ?

And for validating a UTC date "181007" (18th October 2007)

Thanks
0
Comment
Question by:peter1950
  • 3
  • 3
6 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 20101724
Try this pattern, and see if it meets your requirement:

([0-2][0-3]|[0-1][0-9])[0-5][0-9][0-5][0-9]\.\d{3}

Explanation
1) Hours in 24-hour format:   00 - 23 or 00 - 19 -- this can't be one expression or you would get 00 - 29, which is invalid

2) Minutes and seconds:  00 - 59

3) Milliseconds:  Can be any 3 digits only.

Bob
0
 

Author Comment

by:peter1950
ID: 20101854
Thanks.

And if I want to test that the lenght Is exactly 10 chars and that the first 6 chars are digit ?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20101876
\d{6}\.\d{3}

Bob
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:peter1950
ID: 20101922
And if I want to use

([0-2][0-3]|[0-1][0-9])[0-5][0-9][0-5][0-9]\.\d{3}

and

\d{6}\.\d{3} together ?

I try
([0-2][0-3]|[0-1][0-9])[0-5][0-9][0-5][0-9]\d{6}\.\d{3} but it doesn't work.
0
 

Author Comment

by:peter1950
ID: 20101963
Excuse me.

With

([0-2][0-3]|[0-1][0-9])[0-5][0-9][0-5][0-9]

obtain the same result as

\d{6}.

And for validating a date ?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20102181
I don't understand.  Are you looking to combine those two validation expressions into a single one?

Bob
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question