VBScript to JavaScript Equivalent

Results 1 to 2 of 2

Thread: VBScript to JavaScript Equivalent

  1. #1
    Jon Shaw Guest

    Default VBScript to JavaScript Equivalent

    There are a lot of built in functions in VBScript that don’t seem to have JavaScript equivalents. For instance you can use the IsDate() function in VBScript and it will detect that any of the following as a valid date:<BR>07/10/2000<BR>07/10/00<BR>7-10-2000<BR>7-10-00<BR>July 10, 2000<BR>July 10, 00<BR>July 10 2000<BR>July 10 00<BR>Jul 10 2000<BR>Jul 10 00<BR>Jul-10-2000<BR>Jul-10-00<BR>There are probably some more that I haven’t tried also. Being able to detect all of these as dates makes my form much more user friendly and easier for me to work with. With my code I can take anything that a user might enter and format it for insertion into a SQL string. I have seen a question answered here about this subject and the recommendation was to use something like this:<BR>var datePat = /^(d{1,2})(/&#124-)(d{1,2})2(d{2}&#124d{4})$/;<BR><BR>However this does not work with text in the date. My problem is that VBScript doesn’t run in Netscape. Can anyone please advise me as to the equivalent JavaScript version of this VBScript code?<BR><BR>if f.txtDateTo.value &#060;&#062; "" then <BR> if isdate(f.txtDateTo.value) = False then <BR> msgbox "Please reenter the To date in a Date format.",vbOKOnly,"Error" <BR> exit sub <BR> elseif isdate(f.txtDateTo.value) = True then<BR> f.txtDateTo.value = FormatDateTime(f.txtDateTo.value, 2) <BR> end if <BR>end if<BR>

  2. #2
    sm549 Guest

    Default RE: VBScript to JavaScript Equivalent

    There really isn&#039t an equivalent to vb&#039s IsDate(). Sites have their different ways of doing it. You could alternatively use date part comboboxes.<BR><BR>if (isNaN(Number(new Date(document.forms[0].txtDate.value)))){<BR>alert("invalid date.")<BR>}<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts