![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
I am trying to validate if an entry on a form is a date. I have adapted code I found here http://www.codingforums.com/archive/index.php/t-14325 as below but I can't seem the get the results that I am expecting. |
|
function isDate(sDate) { var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/ if (re.test(sDate)) { var dArr = sDate.split("/"); var d = new Date(sDate); return d.getMonth() + 1 == dArr[0] && d.getDate() == dArr[1] && d.getFullYear() == dArr[2]; alert("A Date") } else { alert("Not a Date") return false; } } |
#2
| |||
| |||
|
|
It is better still, if your data-enterers are intelligent, to ask for an ISO 8601 style date, which no-one can mis-understand. |
#3
| |||
| |||
|
|
Dr John Stockton wrote: snip It is better still, if your data-enterers are intelligent, to ask for an ISO 8601 style date, which no-one can mis-understand. Is that to imply that users that use, and understand, a non-ISO 8601 style date are "un-intelligent"? |
|
So, if I have three select lists, properly labeled, can you please tell me how I can get an invalid date if the actual date is assembled on the server? |
#4
| |||
| |||
|
|
Dr John Stockton wrote: It is better still, if your data-enterers are intelligent, to ask for an ISO 8601 style date, which no-one can mis-understand. Is that to imply that users that use, and understand, a non-ISO 8601 style date are "un-intelligent"? I hope you are not that naive and mis-guided by your apparent hatred of the US. |
|
To ensure a date is "valid" is very simple, and employed *very* widely. Even though you, and I alike, can type the date quicker, the problems with date validation is very apparent by the number of sites that use select lists (labeled for day, month, and year) on the web. |
|
So, if I have three select lists, properly labeled, can you please tell me how I can get an invalid date if the actual date is assembled on the server? The only major problem associated with that approach is the year, which a text input can be used for. |
#5
| |||
| |||
|
|
So, if I have three select lists, properly labeled, can you please tell me how I can get an invalid date if the actual date is assembled on the server? Using select elements doesn't prevent the 30th of February. You need extra logic for that. |
![]() |
| Thread Tools | |
| Display Modes | |
| |