|
|
 |
Re: FN-FORUM vbscript
date posted 23rd January 2003 18:26
Erk! That's never going to run, even if you manage to call it. And
if you do get it to run, it's never going to finish :/
Leaving aside the fact that there are probably more elegant ways to do
this, you have at least the following obvious problems:
1) All of your IF statements are missing closing brackets, e.g.
if Not validnamecontents(Request.Form("Name") Then
should be
If Not validnamecontents(Request.Form("Name")) Then
2) Your while...wend loop will never exit, as you're not incrementing the
counter variable
3) ValidatePostcodeContents appears to have picked up some java/php/C
style { } braces instead of If ... Then ... End if
4) So does ValidatePhoneContents
That's just the stuff on a quick first look through. Really there
are neater ways to code a lot of that, using either an array or a
collection to hold the strings etc. etc. but I have to go cook now or
I'll be divorced :)
--
Pete
==== Original Message:
> It is a bit long but here it is - Thanks Pam
>
> Function valid_form()
> Response.write("bbb")
> Dim Name_Error_msg
> Dim Address_error_msg
> Dim Address1_error_msg
> Dim Town_error_msg
> Dim County_error_msg
> Dim Postcode_error_msg
> Dim HomeTel_error_msg
> Dim Email_error_msg
> Dim Comment_error_msg
> Dim Error_msgs
> Error_msgs = 0
> if Not validnamecontents(Request.Form("Name") Then
> Name_Error_msg = "Please complete a valid Name"
> Error_msgs = Error_msgs + 1
> End if
> if Not validaddresscontents(Request.Form("Address") Then
> Address_error_msg = "Please complete a valid Address"
> Error_msgs = Error_msgs + 1
> End if
> if Not validaddress2contents(Request.Form("Address1") Then
> alert("a")
> Address1_error_msg = "Please complete a valid Address or leave blank"
> Error_msgs = Error_msgs + 1
> End if
> if Not validaddresscontents(Request.Form("Town") Then
> Town_error_msg = "Please complete a valid Town"
> Error_msgs = Error_msgs + 1
> End if
> if Not validaddress2contents(Requst.Form("County") Then
> County_error_msg = "Please complete a valid County")
> Error_msgs = Error_msgs + 1
> End if
> if Not validpostcodecontents(Request.Form("Postcode")
> Postcode_error_msg = "Please complete a valid Postcode"
> Error_msgs = Error_msgs + 1
> End if
> if Not validtelephonecontents(Request.Form("HomeTel")
> HomeTel_error_msg = "Please complete your contact telephone number"
> Error_msgs = Error_msgs + 1
> End if
> //CHECK EMAIL ADDRESS IF NOT BLANK (inputbox)
> Dim inputbox = Request.form("Email")
> if Len(inputbox)!= 0 Then
> // Convert inputbox to string
> Dim teststring
> teststring = CStr(inputbox)
> // Check for at least 7 chrs
> if Len(teststring) Email_error_msg = "The email address you have entered is not a valid
> format"
> Error_msgs = Error_msgs + 1
> End if
> // Check for Illegal Characters
> Dim illegalchrs(5)
> illegalchrs = Array("*","£","$","!")
> Dim counter
> counter = 0
> While counter < 5
> if InStr(0, teststring, illegalchrs[counter]) != 0 Then
> Email_error_msg = "You have entered an invalid character in your email
> address"
> Error_msgs = Error_msgs + 1
> End if
> Wend
> // Check for the @ and the dots
> // First check that they both exist
> Dim atpositionback = InStrRev(teststring, [EMAIL REMOVED]
> Dim dotpositionback = InStrRev(teststring, ".")
> Dim atpositionfront = InStr(teststring, [EMAIL REMOVED]
> if atpositionback = 0 Then
> Email_error_msg = "The email address you have entered is not a valid
> format"
> Error_msgs = Error_msgs + 1
> End if
> if dotpositionback = 0 Then
> Email_error_msg = "The email address you have entered is not a valid
> format"
> Error_msgs = Error_msgs + 1
> End if
> if atpositionfront Not = atpositionback Then
> Email_error_msg = "The email address you have entered is not a valid
> format"
> Error_msgs = Error_msgs + 1
> End if
> if atpositionback > dotpositionback Then
> Email_error_msg = "The email address you have entered is not a valid
> format"
> Error_msgs = Error_msgs + 1
> End if
> End if
> if Not validcommentscontents(Request.Forms("Comments")) Then
> Comment_error_msg = "Please complete a valid comments/enquiries field"
> Error_msgs = Error_msgs + 1
> End if
> if Error_msgs > 0 Then
> valid_form = False
> Else
> valid_form = True
> End if
> End Function
> Function validcommentscontents(inputbox)
> Dim teststring
> teststring = CStr(inputbox)
> teststring = Trim(teststring)
> if teststring = "" Then
> validcommentscontents = False
> Exit Function
> End if
> if IsNumeric(teststring) Then
> validcommentscontents = False
> Exit Function
> End if
> validcommentscontents = True
> End Function
> Function validnamecontents(inputbox)
> Dim teststring
> teststring = CStr(inputbox)
> teststring = Trim(teststring)
> if teststring = "" Then
> validnamecontents = False
> Exit Function
> End if
> if IsNumeric(teststring) Then
> validnamecontents = False
> Exit Function
> End if
> if Len(inputbox) < 2 Then
> validnamecontents = False
> Exit Function
> End if
> validnamecontents = True
> End Function
> Function checkvalidaddresscontents(inputbox)
> Dim teststring
> teststring = CStr(inputbox)
> teststring = Trim(teststring)
> if teststring = "" Then
> checkvalidaddresscontents = False
> Exit Function
> End if
> if IsNumeric(teststring) Then
> checkvalidaddresscontents = False
> Exit Function
> End if
> checkvalidaddresscontents = True
> End Function
> Function validaddress2contents(inputbox)
> Dim teststring
> teststring = CStr(inputbox)
> teststring = Trim(teststrimg)
> if teststring = "" Then
> checkvalidaddresscontents = True
> Exit Function
> End if
> if IsNumeric(teststring) Then
> checkvalidaddresscontents = False
> Exit Function
> End if
> checkvalidaddresscontents = True
> End Function
> Function validpostcodecontents(inputbox)
> Dim teststring
> teststring = CStr(inputbox)
> teststring = Trim(teststring)
> if testString = "" Then
> validpostcodecontents = True
> Exit Function
> End if
> if IsNumeric(teststring) Then
> validpostcodecontents = False
> Exit Function
> End if
> if (Len(teststring) < 2 Or Len(teststring.length) > 8) {
> validpostcodecontents = False
> Exit Function
> }
> validpostcodecontents = True
> End Function
> Function validtelephonecontents(inputbox)
> var teststring
> teststring = CStr(inputbox)
> if Trim(teststring) = "" Then
> validtelephonecontents = True
> Exit Function
> End if
> Dim count = 0
> While count < Len(inputbox)
> Dim c = Mid(inputbox, count, 1)
> if ((c Not = " ") And (c Not = "-") And Not IsNumeric(c)) Then
> validtelephonecontents = False
> Exit Function
> }
> count = count + 1
> Wend
> return 0
> End Function
>
> '
> NTMail K12 - the Mail Server for Education
> ========
> Freelancers and Freelance Jobs: http://www.freelancers.net
> Advertise with Freelancers.net http://www.freelancers.net/advert.php
> To unsubscribe please email: [EMAIL REMOVED]
> If you have difficulties unsubscribing please email: [EMAIL REMOVED]
|
 |
|