Reqular Expression to validate a date

by Semicton 16. February 2010 22:12

Regular expressions treat numbers as text so you can't simply check a series of numbers and ask the expression: Is the value of 100 between a value of 0 to 255?  To understand better, follow the explanation below.

This expression validates and matches mm/dd/yyyy

(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d

Lets break this up a bit.

Why so many ()'s ?

No, these are not emoticons :) I enclose each expression in parenthesis because I am using a pipe.  The pipe is basically an OR operator but is call an option.  If I had not surrounded the expression in parenthesis, the expression would split the regular expression into two separate options. 

MONTH

0[1-9]

The first part contains the number zero.  This is telling the expression that the zero is required and the first string matches a number between 01 and 09.

1[012]

The second part shows the number one is required if the string matches 10, 11 or 12.

final expression for the month: 

(0[1-9]|1[012])

The day expression is very similar to the month expression.

Day

The first matches the numbers 01 through 09, the second 10 through 29, and the third matches 30 or 31. Notice how each value is checked for and split by a pipe |  This does not work for leap years!

Final expression for Day:

(0[1-9]|[12][0-9]|3[01])

Year

(19|20)

The first two digits must match 19 or 20. Notice that only the match for the first two digits have an option pipe and that they are enclosed in parenthesis.

\d\d

Next I am looking for any two digits represented by \d for anyone one digit.

Final expression for year:

(19|20)\d\d

Deliminator

Finally, Each expression must have a matching Deliminator. Notice how I allow a space in the available matches.

[-  /.]

Fun!

Final Expression

Example:

(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d

will find a match for 02/12/2008.

 

Tags:

Sandbox

Facebook Application

by Semicton 16. February 2010 15:54

My first Facebook application!  It was actually very simple.  It's simply a portion of my own site running as an iframe in  facebooks page. 

Check it out:  http://apps.facebook.com/semictontest

Tags:

Sandbox

Desktop Binary Clock

by Semicton 25. December 2009 03:21

This is one of the first .NET applications I created about 6 years ago.

I have since lost the source code, but you can decompile the executable as it is obviously not obfuscated.  This was programmed in VB.NET  1.1 .NET Framework while I prepared for my Cisco CCNA exam.  I have since then jumped to C# for reasons I will explain in another post.

You might be asking yourself this question..

What are you getting at?

The reason I am blogging this file download is becuase I am absolutely ashamed of the code it contains. 

It's amazing what you can learn in 6 years.  Bit shifting, events, delegates, patterns and practices, and much more come to mind.  While writing the code for this project, I followed the math.  I was not as interested in the code that solved the problem as much as I was interested in the math to solve the problem.  I even wrote a debugger to display the math for each octact (no longer in the code). 

When I developed this application I was a pure VB6 Event programmer that knew nothing about patterns and practices, delegates, or even classes. I wrote this application as one monolithic executable just as I would have written it as a VB6 application 10 years ago.

Yet this application still runs on Windows 7 with no modifications 6 years after it was compiled. 

Microsoft .NET Framework

If this were a program developed in VB6 in 1997 and an end user tried to run it in the year 2002 I'll bet the average user during that time would not be as lucky as a .NET user today. 

Of course the rules change if you are a developer, but that doesn't mean the technology sucks.

As I type this blog I can't help but remind myself one important thing. I refuse to stop learning, and that is a good thing.

And hey, If my code can continute to keep track of time 6 years after it was written, I should be on the right track, right?

I hope so.  Cheers.

Sorry for the poor video quality. I've misplaced my desktop recording software !

This binary clock requires the 1.1 .NET framework to run.

File Download:
BinaryClock.zip (13.96 kb)

Screenshot

Tags:

Sandbox

Internet Lamp

by Semicton 23. December 2009 00:34

This is a module I created in C# using Sockets and TCP.  Pressing the button will turn on my house lamp from any where in the world.  There are four parts to this application:

  1. A client service installed on my local PC uploads and stores my IP address to a SQL server on da' net.   If the client service notices it's IP has changed, It updates the database.
  2. A socket server app controlling phidgets and accepting TCP connections.  Once a connection is created, I parse the message and turn on my lamp via a relay switch.
  3. A client on running here on this web page.  The client querys the database for my IP address first, and then creates a connection to my desktop.
  4. The client here on this web page then sends a command to my socket server on my desktop that turns on my lamp.

Watched the video? Try it yourself:

Turn on my home lamp

Tags:

Sandbox

Powered by Semicton 1.5.0.7

Latest Downloads:

File Name Downloads
2009/12/scribd.zip 316
2009/12/BinaryClock.zip 261