Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validation rule not working 1

Status
Not open for further replies.

loveday

Programmer
Sep 19, 2004
106
US
I have been trying to modify my code so it checks for each payment type before the processing card.

I am doing the processing with the code below:

Code:
If (Request.Form("paymentm") = 'MC' OR Request.Form("paymentm") = 'Disc' OR Request.Form("paymentm") = 'Visa') AND (Request.Form("cardno") = "" OR len(Request.Form("cardno")) < 16 ) Then
	Response.Redirect "checkout.asp?msg=" & Server.URLEncode ("Mastercard or Visa or Discover cards must be 16 digits.")
Elseif (Request.Form("paymentm") = 'AmEx') AND (Request.Form("cardno") = "" OR len(Request.Form("cardno")) < 15 ) Then
	Response.Redirect "checkout.asp?msg=" & Server.URLEncode ("American Express card must be 15 digits.")
Elseif (Request.Form("paymentm") = 'Diners') AND (Request.Form("cardno") = "" OR len(Request.Form("cardno")) < 14 ) Then
	Response.Redirect "checkout.asp?msg=" & Server.URLEncode ("Diners club card must be 14 digits.")

Elseif Request.Form("cardname") = "" OR len(Request.Form("cardname")) <=6 Then
	Response.Redirect "checkout.asp?msg=" & Server.URLEncode ("Please fill in a correct credit card name.")
End if
This is not working so far.

I am getting this error:

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
process.asp, line 120, column 31
If (Request.Form("paymentm") = 'MC' OR Request.Form("paymentm") = 'Disc' OR Request.Form("paymentm") = 'Visa') AND (Request.Form("cardno") = "" OR len(Request.Form("cardno")) < 16 ) Then


Thanks in advance for your assistance
 
You can't use single quotes, they are not string delimiters in VBScript. You need things like "MC" instead of 'MC'.
 
Also, it's inefficient to refer to a form element over and over. It would be better (and easier to read and debug) if you did something like this:
Code:
Dim Payment, CardNo, CardName
Payment = Request.Form("paymentm")
CardNo = Request.Form("cardno")
CardName = Request.Form("cardname")

If (Payment = "MC" OR Payment = "Disc" OR Payment = "Visa") AND (CardNO = "" OR Len(CardNo) < 16 ) Then
    Response.Redirect "checkout.asp?msg=" & Server.URLEncode ("Mastercard or Visa or Discover cards must be 16 digits.")

ElseIf (Payment = "AmEx") AND (CardNo = "" OR len(CardNo) < 15 ) Then
    Response.Redirect "checkout.asp?msg=" & Server.URLEncode ("American Express card must be 15 digits.")

ElseIf (Payment = "Diners") AND (CardNo = "" OR len(CardNo) < 14 ) Then
    Response.Redirect "checkout.asp?msg=" & Server.URLEncode ("Diners club card must be 14 digits.")

ElseIf CardName = "" OR Len(CardName) <=6 Then
    Response.Redirect "checkout.asp?msg=" & Server.URLEncode ("Please fill in a correct credit card name.")

End if
 
Yea, you are absolutely right.

Thanks for not only resolving it but pointing a more efficient way.

Your help is appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top