Will66 Posted February 10, 2008 Posted February 10, 2008 How to check an form field is a valid date? eg, if a user has entered 10-7-08 into a field name "AB8": $oForm = _IEFormGetCollection ($oIE, 0) $oForm_date = $oForm("AB8").value If _DateIsValid($oForm_date) Then MsgBox( 4096, "Valid Date", "The specified date is valid." & $oForm_date) Else MsgBox( 4096, "Valid Date", "The specified date is invalid." & $oForm_date) EndIf _DateIsValid requires yyyy/mm/dd format but the field entry dd/mm/yyyy
Achilles Posted February 10, 2008 Posted February 10, 2008 (edited) Just rewrite the _DateIsValid function using the default _DateIsValid()... like this: (untested) Func _DateIsValidEx($date) $split = StringSplit($date, "/") $temp = $split[3] & '/' & $split [2] & '/' & $split[1] Return _DateIsValid($temp) EndFunc Edited February 10, 2008 by Piano_Man My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Will66 Posted February 10, 2008 Author Posted February 10, 2008 (edited) Thanx, I should be more clear....I guess what i'm really trying to do is allow any date type entry into the field. For example with vbscript a user can enter many date formats eg: 10-7-08 or 10 feb-08 or 10/7/08: CODE <td>Fortnight Ending:</td><td><input name="AB8" value="" onchange="validDate(this,this.value)"></td> <script type="text/vbscript"> function validDate(dfield,dd) if not isDate(dd) then msgbox "'" & dd & "' is not a valid date!",0,"Error" else mydate = FormatDateTime(dd,0) dfield.value=mydate end if end Function Edited February 10, 2008 by Will66
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now