To do this, create a form page called form.asp and copy the below code into your page:
In this case, we will make the Email, Subject, and Comments fields all required.
Next, create a page called confirm.asp and copy the below code into your page:
<% DIM strEmail strEmail = Request.Form("Email") IF strEmail <> "" AND inStr(strEmail,"@") <> 0 AND inStr(strEmail,".") <> 0 THEN
' Enter form to database or send via email
ELSE
Response.Write "
Please click Back on your browser and complete the following field:
"IF strEmail <> "" THEN
ELSE
Response.Write "• Email
"
END IF
IF inStr(strEmail,"@") <> 0 THEN
ELSE
Response.Write "• You entered an invalid Email Address
"
END IF
IF inStr(strEmail,".") <> 0 THEN
ELSE
Response.Write "• You entered an invalid Email Address
"
END IF
END IF
%>
This script verifies that the email address contains a "@" and a "." or it displays a "Click "You Back on your browser..." message. You can obviously take this much further if you wanted to depending on your situation. If you only wanted to except emails that ended in ".com" or ".de" you could enter ".com" in place of the "@" symbol and change the "<> 0" to "= 0". Many companies offer free newsletters that users can subscribe to, but they will not let you subscribe with a free email account like hotmail, yahoo, etc. You could simply replace the "@" symbol with "hotmail" to prevent that. So even though this script will not actually verify that the email address entered is totally valid, it at least greatly reduces the amount of potential errors you could have to deal with. Happy validating!
No comments:
Post a Comment