![]() |
Validate Date field MM/DD/YYYY with legit date
Hi All,
I've been searching all over the web and plugging in pieces of code that I have found that would accomplish a field validation maknig sure the date is in the right format and it is an actual date. Not 12/45/2012. This is the latest piece of code I've taken from the web but this still isn't working: Code:
function isValidDate(dateString)Code:
function validateForm( frm ) |
The simplest way to validate a date in mm/dd/ccyy format in JavaScript is to load it into a date object and then test to make sure that the day, month and year in the date object are the same as those in the original string.
Code:
function isValidDate(dateString)Are you sure that you are only passing the date without any leading or trailing spaces? Since you don't trim off any spaces a single space added to the date would cause it to fail validation. |
This topic comes up quite often in the forum . Try using the search feature.
Code:
<script type = "text/javascript">Code:
<script type = "text/javascript">Quizmaster: What relation was King Edward VIII to the Queen? Contestant: Husband. |
I definately need MM/DD/YYYY and I have that format written on form.
Will both of these accomplish that, I am going to give them a try in a moment. Thank you for the responses. |
Quote:
|
Neither are working or maybe I'm missing something with the space thing but I really don't know much.
I use forums and google searches to find code and i'm usually good enough to tweak it to what i need but I'm really struggling with this. All I can tell you is I have an effective date field and it needs to be MM/DD/YYYY and I had this code which made sure it was in the right format: Code:
var datechk = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/But nothing to make sure it was a valid date. Should mention I tried both your pieces of code and even with a valid date I'm getting an error so again it might be a space thing...i really couldnt tell you...thanks guys |
Quote:
|
haha well I must be missing something then
|
Why do you say tha the scripts do not work? If you copy them into your browser and run them you will see that they do. Is the problem that you are passing the dates to the script in the wrong format?
|
I very well could be.
When I use your code: Code:
<script type = "text/javascript">Why is that? BTW this is an html form...I don't know if that makes a difference. |
I am now trying this:
Code:
function isValidDate(dateString) { Code:
function validateForm( frm ) |
Quote:
Code:
var nd = new Date(yr,mm,dd); |
Quote:
|
Quote:
var strDate1 = "01/31/2012"; // USA date format var strDate2 = "2/31/2012"; You must pass the date in the correct format. |
Do I need to mention my date field (EffectiveDate) someone in this code so it knows where to pull the date from?
Aside from that question, is this code set up to validate the date in MM/DD/YYYY format? Code:
function checkValidDate(yr,mmx,dd)The two lines in green are the same so how does that work? And I have this piece of code in my function to validate the form: Code:
if ( ! checkValidDate( frm.elements["EffectiveDate."] ) )Again I am a beginner with this type of stuff so I'm trying to figure it out. I appreciate your guys patience with me...I know sometimes that isn't easy. |
| All times are GMT +1. The time now is 04:10 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.