VBScript Email Validation
Not only is it important to use Javascript client side validation it
is also important to use server side (ASP) validation as well. Visitors
may have Javascript disabled in their browser so it's very important to
use server side validation as a backup. Below is the code for a function
'IsValidEmail' that will check the syntax of an email. Note that the function
will only check for the proper syntax it will not check to make sure if
the email really exists.
<%
Function IsValidEmail(emailAddress)
Dim ValidEmail, emailParts, iLoopCounter, emailChar, acceptableChars, last2Chars
ValidEmail = True
acceptableChars="abcdefghijklmnopqrstuvwxyz.-_@"
emailParts = Split(emailAddress, "@")
If UBound(emailParts) <> 1 Then
ValidEmail = false
Else
If Len(emailParts(0))<1 OR Len(emailParts(1))<4 Then
ValidEmail = false
End If
If Left(emailParts(0), 1)="." Then
ValidEmail = false
End If
If InStr(emailParts(1), ".") <= 0 Then
ValidEmail = false
End If
last2Chars=Right(emailParts(1),2)
If InStr(last2chars,".") Then
ValidEmail = false
End If
If InStr(emailParts(1), "_") >0 Then
ValidEmail = false
End If
End If
For iLoopCounter = 1 to Len(emailAddress)
emailChar = Lcase(Mid(emailAddress, iLoopCounter, 1))
If InStr(acceptableChars, emailChar) = 0 and Not IsNumeric(emailChar)
Then
ValidEmail = false
End if
Next
If InStr(emailAddress, "..") > 0 Then
ValidEmail=false
End If
If InStr(emailAddress, "@.") > 0 Then
ValidEmail=false
End If
IsValidEmail=ValidEmail
End function
%>
Using the function above here are 2 examples:
<% Response.write IsValidEmail("test@testemail") %>
Output:
false
<% Response.write IsValidEmail("test@testemail.com")
%>
Output:
True You may want to read our tutorials on useful VBScript
functions and Arrays to help you
understand the code better.
Using Regular Expressions to validate an email.
Membership Software Integrates with PayPal
- Plug and play Membership script.
- Recurring subscriptions or one time payment.
- Up to 3 levels of membership subscription.
- Easy set up and admin with free installation.
- Works with PayPal.
- Receive updates and add-ons for 2 years.
- 1st class support and customization available.
- Can be customized to support more levels.
- Saves you hours and hours of development time and money.
- PURCHASE YOUR COPY TODAY
If you have any code snippets to share with full credit given then send an email to Codesnippets - You'll receive full credit and a link back to your site.
Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.
|