Sign in to follow this  
Followers 0
Will66

How to check an IE form field is a valid date?

3 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Will66

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0