473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

validate a date using a regular expression

Hello,
I would like to validate a date in a textbox on the onChange event.
The date must be in the format 01/01/2007

I would like to use a regular expression to validate it but I'm not
very familiar with them. How can I do it ?

Thanks

Jun 12 '07 #1
3 7155

samuelberthe...@googlemail.com napsal:
Hello,
I would like to validate a date in a textbox on the onChange event.
The date must be in the format 01/01/2007

I would like to use a regular expression to validate it but I'm not
very familiar with them. How can I do it ?

Thanks
var regExp = /^\d{2}\/\d{2}\/\d{4}$/;
var date = "01/01/2007";

if(regExp.test(date)) {
alert('yep its correct date');
} else {
alert('this is not correct date');
}

This regexp will only test format not date. (correct date will be
99/99/9999).

Jun 12 '07 #2
thanks you ! it works.

Jun 12 '07 #3
In comp.lang.javascript message <11**********************@o11g2000prd.go
oglegroups.com>, Tue, 12 Jun 2007 10:11:46,
sa*************@googlemail.com posted:
>I would like to validate a date in a textbox on the onChange event.
The date must be in the format 01/01/2007
That's a really silly format. It could represent, in that order, 1st
Jan 2007 or Jan 1st 2007. Now consider the following day ... . Numeric
dates should be ISO 8601.
>I would like to use a regular expression to validate it but I'm not
very familiar with them. How can I do it ?
You can easily validate the pattern thus, but not *easily* the date
itself. However, validating the date itself after a pattern test is
trivial, once the principle is realised. See below.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Eddie | last post by:
I need to validate a text input field. I just want to say if user enters 93101 or 93102 or 93103 or 93105 or 93106 or 93107 or 93108 or 93109 or 93110 or 93111 or 93116 or 93117 or 93118 or...
4
by: Frank Rocco | last post by:
Hello, What is the best way to validate a textbox to see if it contains a valid date or a valid time or both? Thanks Frank
2
by: Bogdan Zamfir | last post by:
Hi, I want to use RegularExpressionValidator to validate a date I want to let user to enter date in the following format one or two digits for day one or two digits for month two or four...
2
by: Ori | last post by:
Hi, I'm looking for a good way to validate a US phone number and i though using regular expression for this. I want to support 3 different ways to enter a phone number: 1.Local Phone : 888-8899...
6
by: RSB | last post by:
Hi Every one Need some help to Validate the Date i have in the Form. ALso how to Convert the Date Data i read from table to yyyy/MMM/dd format. Thanks RSB
7
by: Chris Kennedy | last post by:
Does anyone know a regular expression that will validate the file extension but also allow multiple file extensions if necessary. It also needs to be case insensitive. Basically, what I want is to...
5
by: Ryan | last post by:
HELLO I am using the following MICROSOFT SUGGESTED (somewhere on msdn) regular expression to validate email addresses however I understand that the RFP allows for "+" symbols in the email address...
5
by: Ganesh | last post by:
Hi There, I need to validate email address with regular expression control, i tried something like this ^+*@*\.*$ but i need to validate even if it is blank, it should say invalid email,...
5
by: shapper | last post by:
Hello, What is the Regex expression to validate a date time format as follows: dd-mm-yyyy hh:mm:ss An example: 20-10-2008 10:32:45
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.