%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% option explicit %>
<% 'ASPAjax.Path="/aspajax/" ASPAjax.Open() ' Set up ASPajax %>Using ASP AJAX to validate forms has many advantages.
In this tuturial, the form is validated at server level - yet the client has 'immediate' feedback.Form field values are not wiped on post back - reducing user frustration.
<% ASPAjax.Close() ' Close up ASPajax at the end of all HTML%> <% Function ValidateForm Dim Valid If Request.Form("submit")<>"" then Valid = true if not isValidEmail (Request.Form("email")) then Message1 = "* Please Enter a Valid Email Address" : Valid = False if LCASE(Request.Form("email")) <> LCASE(Request.Form("email2")) then Message2 = "* Email Addresses do not Match": Valid = False if not isValidPassword (Request.Form("password")) then Message3 = "* Passwords should be at least 6 characters long, and contain at least 1 number.": Valid = False End If ValidateForm = Valid End Function ' Helper Functions for the form Function isValidEmail(myEmail) dim isValidE dim regEx isValidE = True set regEx = New RegExp regEx.IgnoreCase = False regEx.Pattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$" isValidE = regEx.Test(myEmail) isValidEmail = isValidE End Function function isValidPassword(myString) myString = myString&"" if (Len(myString)<6) then isValidPassword = false : exit function dim isValidE dim regEx isValidE = True set regEx = New RegExp regEx.IgnoreCase = False regEx.Pattern = "[0-9]" isValidE = regEx.Test(myString) isValidPassword = isValidE End Function %>