HELP PLEASE! Problem with Classic ASP (Vbscript)?

  • Thread starter Thread starter Robyn in the Hoode
  • Start date Start date
R

Robyn in the Hoode

Guest
I am having problems getting the following VBScript function to work.

I am testing the value of a what is entered in a text field, so when it is sent from the previous form it return a true or false value.

However when I enter "u" for the function to test the string as a name the page does not display and I get a type mismatch error!

Can anybody shed light on the matter, I would be greatful for any help at all!

<% @Language=VBScript %>
<% Option Explicit

'*******************************************
Function IsDataInValid(varFData, strFFType)
'Purpose: function to test all form field returned values
'Inputs:
'varFDatathe variable to test
'strFFTypethe variable type to test for
's = string (including punctuation marks)
'u = name (e.g. first name, family name)
'd = date
't = time
'n = decimal
'i = integer
'p = phone
'e = email
'c = postcode
'Returns:True if no match
'False if no error in value
'
'Notes:the test for string types excludes strings that convert to numeric values
'*******************************************
'set default return value to FALSE, only changed if we find an error
IsDataInValid = False

Select Case strFFType
Case "s" 'test string using for non-zero length and not numeric
If RegExpTest("^\S+$",varFData) = False Or IsNumeric(varFData) Then IsDataInValid = True
Case "u" 'test a 'name' class of string
If RegExpTest("^[A-Za-z]+$",varFData) = False Then IsDataInValid = True
Case "d" 'test for date using IsDate
If Not IsDate(varFData) Then IsDataInValid = True
Case "t" 'test for time using IsDate
If Not IsDate(varFData) Then IsDataInValid = True
Case "n" 'test for decimal using IsNumeric and includes decimal point
If RegExpTest("^\-?[0-9]*\.?[0-9]*$",varFData) = False Then IsDataInValid = True
Case "i" 'test integer using regular expression
If RegExpTest("^\-?[0-9]+$",varFData) = False Then IsDataInValid = True
Case "p" 'test phone using regular expression
If RegExpTest("^([0-9]{5})-| ([0-9]{6})",varFData) = False Then IsDataInValid = True
Case "e" 'test email using non-zero length string and @ and .
If RegExpTest("^([0-9a-zA-Z]+)([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)\.([0-9a-zA-Z]+)",varFData) = False Then IsDataInValid = True
Case "c" 'test for postcode
If RegExpTest("^[A-Za-z]{2}[0-9]{1,2} [0-9]{1,2}[A-Za-z]{2}$",varFData) = False Then IsDataInValid = True
End Select
End Function
'
Dim strFirstName, strSurname, strAddress1, strAddress2, strAddress3, strAddress4, strPostCode, strEmail, strTel, strPw, blnFirstName, blnSurname, blnPostcode, blnTel, blnEmail
'

'
strFirstName = Request.QueryString("txtFirstName")
strSurname = Request.QueryString("txtSurname")
strAddress1 = Request.QueryString("txtAddress1")
strAddress2 = Request.QueryString("txtAddress2")
strAddress3 = Request.QueryString("txtAddress3")
strAddress4 = Request.QueryString("txtAddress4")
strPostCode = Request.QueryString("txtPCode")
strEmail = Request.QueryString("strEmail")
strTel = Request.QueryString("txtTel")
'The above assigns a value to the each variable by requesting the value of each form element
blnFirstName = IsDataInValid(strFirstName, "u")
'The boolean value of the outcome of testing is assigned to the variables above

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>AandB Home Page</title>
<link rel="STYLESHEET" type="text/css" href="abpans.css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0">
<img src="images/cook_shop.gif" alt="A and B Pans" width="500" height="60" border="0">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr><!-- navigation cell -->
<td width="25%" rowspan="3" valign="top" nowrap>
<!--- content here --->
</td>
<!-- main cell -->
<td valign="top">
<p>blnFirstName <%= blnFirstName %></p>
</td>
</tr>
</table>
</body>
</html>
 
Back
Top