tags:

views:

20

answers:

2

I tried to control email address and reviewer's name with the following code but I received this error.

Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'Mid'

Cant I compare Mid(REVIEWEREMAIL, InStr(1, REVIEWEREMAIL, "@", 1), 1) to "@"?

  If Len(REVIEWERNAME) < 2 Then
   with response
    .write "Error! Please fill in valid name. <br />"
   end with
  ElseIf Len(REVIEWEREMAIL) < 3 Then
   with response
    .write "Error! Please fill in valid email address. <br />"
   end with
  ElseIf Mid(REVIEWEREMAIL, InStr(1, REVIEWEREMAIL, "@", 1), 1) <> "@" Then
   with response
    .write "Error! Please fill in valid email address. <br />"
   end with
  Else

               insert...

End If
+1  A: 

You can simplify that last ElseIf like this:

ElseIf InStr(REVIEWEREMAIL, "@", vbTextCompare) = 0 Then

Because as written, you're solely checking if there is a @ in the email address provided.

If you're concerned about further validating the email addresses you get, there is a great deal written about using regular expressions to validate email addresses. One example: http://www.codetoad.com/asp_email_reg_exp.asp

Adam Bernier
+1  A: 

The likely reason is that REVIEWEREMAIL is null -- in which case your first IF condition isn't going to catch it as intended. Len() of a null doesn't return an integer 0.

The "classic" ASP cheat for that is to change your null variable to an empty string with something like

REVIEWEREMAIL = REVIEWEREMAIL  & ""

which will give back LEN = 0

Beyond that, you may want to look for a regular expression online that will check for valid email values.

LesterDove
This was basically my problem. I was calling Mid in a for loop which was retrieving each character from the string. I thought the Mid call was 0 based but it actually starts at 1 so calling mid(myStr, 0, 1) will return the "Invalid procedure call or argument: 'Mid'" error whereas mid(myStr, 1, 1) is the correct call to get the first character of a string.
Rob Segal