<%@ language="VBScript" %> <% Option Explicit %> <% ' Dim some Page scope variables. dim blnIsPostback, blnIsValid ' And some to recieve the form field values. dim Salutation, FirstName, Surname, Address1, Address2, State, Zip, Country dim Phone, IPAddress, Email, Age ' Plus 1 to store any Validation Error messages dim strValidationMessage strValidationMessage = "" %> <!-- #Include file="Validators.asp" --> <% ' Determine whether or not this page is being posted back to itself ' and if it is then determine whether or not the form values Validate. if not isEmpty(Request("cmdSubmit")) then blnIsPostback = true blnIsValid = ValidateFormValues() else blnIsPostback = false end if sub Page_Load() ' This is the main event for the page. If blnIsPostBack Then ' The page is being posted back to itself. ' Do something here maybe call a state maintenance function. If blnIsValid Then ' The page is being posted back to itself AND the data has been validated. Response.Redirect "Thankyou.asp" End If ' The page is being posted back to itself BUT the data was not validated. ' Do something here, maybe prepare a detailed error message. Else ' The page is not being posted back to itself. ' Maybe set some default values for the form fields. End If end sub Private function ValidateFormValues() ' This function validates the user entry if the page is being posted back and returns True if ' the data validates and False if there are errors. ' Grab the values for the fields that we wish to validate. FirstName = Request("FirstName") ' Required field. Surname = Request("Surname") ' Required field. Address1 = Request("Address1") ' Required field. Address2 = Request("Address2") ' Required field. Phone = Request("Phone") ' Pattern match. Zip = Request("Zip") ' Pattern match (4 numbers). IPAddress = Request("IPAddress") ' Pattern match. State = Request("State") ' Pattern match (1 of 6 possible values). Email = Request("Email") ' Pattern match. Age = Request("Age") ' Range match (between 10 and 40). ' Compile a validation message. ' Do our Required Field Tests. strValidationMessage = strValidationMessage & RequiredFieldValidator(FirstName, "FirstName") strValidationMessage = strValidationMessage & RequiredFieldValidator(Surname, "Surname") strValidationMessage = strValidationMessage & RequiredFieldValidator(Address1, "Address1") strValidationMessage = strValidationMessage & RequiredFieldValidator(Address2, "Address2") ' Do our Regular Expression Tests. strValidationMessage = strValidationMessage & RegularExpressionValidator(Phone, "Phone", "\([0-9]{2}\)(\s?)[0-9]{4}-[0-9]{4}") strValidationMessage = strValidationMessage & RegularExpressionValidator(Zip, "Zip", "\d{4}") strValidationMessage = strValidationMessage & RegularExpressionValidator(IPAddress, "IPAddress", "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") strValidationMessage = strValidationMessage & RegularExpressionValidator(State, "State", "^(QLD|NSW|VIC|SA|WA|TAS)$") strValidationMessage = strValidationMessage & RegularExpressionValidator(Email, "Email", "^([\w-_]+\.)*[\w-_]+@([\w-_]+\.)+[a-z]{2,3}$") ' Do our Range Tests. strValidationMessage = strValidationMessage & RangeValidator(Age, "Age", 10, 40) ' Check to see if errors occurred. if len( strValidationMessage ) < 1 then ValidateFormValues = True else ValidateFormValues = False end if end function ' Fire the Page_Load event call Page_Load() %> <html> <head> <title>Make .NET migration easy!!</title> </head> <body topmargin='0' leftmargin='0' marginwidth='0' marginheight='0'> <% ' Display any error messages to the user If len(strValidationMessage) > 1 Then Response.Write "<center><div style=""width: '90%'; background-color: 'palegoldenrod'; color: 'red'; font-weight: 'bolder'; "">" & vbCrLf Response.Write strValidationMessage & vbCrLf Response.Write "</div></center><br />" & vbCrLf End If %> <br /> <blockquote> <table> <FORM METHOD=post name="frmNETTest"> <tr> <td> Salutation: </td> <td> <SELECT NAME="Salutation" SIZE="1"> <option value="" selected="selected">Blank</option> <option value="Mr.">Mr.</option> <option value="Ms.">Ms.</option> <option value="Mrs.">Mrs.</option> <option value="Dr.">Dr.</option> </SELECT> </td> <td> </td> </tr> <tr> <td> First Name: </td> <td> <INPUT NAME="FirstName" size="30" value="<%=FirstName%>" /> </td> <td> This is a required field </td> </tr> <tr> <td> Surname: </td> <td> <INPUT NAME="Surname" style="HEIGHT: 22px; WIDTH: 256px" value="<%=Surname%>" /> </td> <td> This is a required field </td> </tr> <tr> <td> Address 1: </td> <td> <INPUT NAME="Address1" style="HEIGHT: 22px; WIDTH: 256px" value="<%=Address1%>" /> </td> <td> This is a required field </td> </tr> <tr> <td> Address 2: </td> <td> <INPUT NAME="Address2" style="HEIGHT: 22px; WIDTH: 256px" value="<%=Address2%>" /> </td> <td> This is a required field </td> </tr> <tr> <td> State: </td> <td> <INPUT NAME="State" style="HEIGHT: 22px; WIDTH: 199px" value="<%=State%>" /> </td> <td> You must enter 1 of: 'QLD' or 'NSW' or 'VIC' or 'SA' or 'WA' or 'TAS' </td> </tr> <tr> <td> Zip: </td> <td> <INPUT NAME="Zip" value="<%=Zip%>" /> </td> <td> You must enter 4 numbers. </td> </tr> <tr> <td> Phone: </td> <td> <INPUT NAME="Phone" value="<%=Phone%>" /> </td> <td> The phone number must match the pattern: (##) ####-#### </td> </tr> <tr> <td> IP Address: </td> <td> <INPUT NAME="IPAddress" value="<%=IPAddress%>" /> </td> <td> The IP Address must match the pattern: #[##].#[##].#[##].#[##] </td> </tr> <tr> <td> Email: </td> <td> <INPUT NAME="Email" style="HEIGHT: 22px; WIDTH: 265px" value="<%=Email%>" /> </td> <td> The e-mail pattern will be checked </td> </tr> <tr> <td> Age: </td> <td> <INPUT size="2" NAME="Age" TYPE=text value="<%=Age%>" /> </td> <td> The Age must be between 10 & 40 (Sorry Bill ;) ) </td> </tr> <tr> <td align="right"> <br /><INPUT TYPE="submit" Value="Submit" name="cmdSubmit" /> </td> <td colspan="2"> <!-- spacer --> </td> </tr> </form> </table> </blockquote> </body> </html>