<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% option explicit %> <% 'ASPAjax.Path="/aspajax/" ASPAjax.Open() ' Set up ASPajax %> ASP AJAX form processing and validation tuturial. <% ' Create an UpdatePanel to AJAX enable the entire form automatically. Dim myPanel Set myPanel = ASPAjax.CreateUpdatePanel myPanel.Id = "VALIDATION_FORM" myPanel.Open Dim Message1 , Message2 , Message3 %> <% If Request.Form("submit")<>"" And ValidateForm() then 'process form %>

Thanks for your submission

<% else %>
" /> <%=Message1%>
"/> <%=Message2%>
" /> <%=Message3%>

<% end if %> <% myPanel.Close 'clean up Set myPanel = nothing %>

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 %>