Regular Expressions

Associate
Joined
20 Jan 2005
Posts
386
Location
Crewe, Cheshire
Hi folks,

Is anyone familiar with regular expressions?

I have created an ASP.NET site, and need to validate various dates. I need to have three expressions each for dd/mm/yyyy, dd/mmm/yyyy, and the full blown date as a string.

I have found these expressions on regexlib, but can I put them all together in one regularexpressionvalidator?

If so, how?

Thanks
 
Thanks, but I can't really do that.

It's for an online application form I am working on for a college. Two of the sections ask for their qualifications and work experience.

I'm trying to cover all the possibilities, as they may not remember the exact day they did their work experience or achieved their qualifications.

The possiblities I have come up with are:

12/02/1992
12 Feb 1992
12 February 1992
Feb 1992
February 1992

As I said before, I have the expressions to do this, but rather than having three seperate validators, I was wondering if there was a symbol I could use to place it all into one somehow.
As I have no idea when it comes to regular expressions.
 
Agree with marc2003 if it doesn't matter if the person has forgotten the exact date just give them two drop down lists or two text boxes to select/enter the month and year.

If your still not convinced try the asp:CustomValidator and create a javascript method on your page which validates it. Far easier than regex.
 
can you post the regexp patterns you currently have.

You can logically group regexp clauses so you will be able to have a single expression perform what you require.

Regular expressions are incredibly powerful, there are whole books hundreds of pages long devoted simply to them. Many people don't realise.
 
Well I did give in and decide to tell them what format to use, but if I can get regular expressions working, I would rather use them.

For short date (dd/mm/yyyy)
Code:
^\d{1,2}\/\d{1,2}\/\d{4}$

For medium - long date (12 Feb 1992, 12 February 1992)
Code:
^((31(?!\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\b|t)t?|Nov)(ember)?)))|((30|29)(?!\ Feb(ruary)?))|(29(?=\ Feb(ruary)?\ (((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\d|2[0-8])\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\b|t)t?|Nov|Dec)(ember)?)\ ((1[6-9]|[2-9]\d)\d{2})$

For just month and year (Feb 1992, February 1992)
Code:
^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\,*\s\s*\d{4}$|^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\,*\s\d{4}$|^(January|February|March|April|May|June|July|August|September|October|November|December)\,*\s\d{4}$|^(january|february|march|april|may|june|july|august|september|october|november|december)\,*\s\d{4}$
 
Back
Top Bottom