1 2 Private Function ValidateForm() As FormValidity 3 4 Dim MyReturn As New FormValidity 5 Dim ReturnString As New StringBuilder 6 Dim IsValidForm As Boolean = True 7 8 If (txtFirstName.Text = "") Then 9 ReturnString.Append("First Name") 10 txtFirstName.Attributes.Add("style", "background-color:#EBECED") 11 txtFirstName.Focus() 12 IsValidForm = False 13 End If 14 15 If (txtLastName.Text = "") Then 16 ReturnString.Append(", Last Name") 17 txtLastName.Attributes.Add("style", "background-color:#EBECED") 18 If (IsValidForm) Then txtLastName.Focus() 19 IsValidForm = False 20 End If 21 22 Dim InputEmail As String = txtEmail.Text 23 Dim EmailExpression As String = "^[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]$" 24 Dim Re As New Regex(EmailExpression) 25 26 If (Not Re.IsMatch(InputEmail)) Then 27 ReturnString.Append(", E-mail Address") 28 txtEmail.Attributes.Add("style", "background-color:#EBECED") 29 If (IsValidForm) Then txtEmail.Focus() 30 IsValidForm = False 31 End If 32 33 If (txtAdd1.Text = "") Then 34 ReturnString.Append(", Address 1") 35 txtAdd1.Attributes.Add("style", "background-color:#EBECED") 36 If (IsValidForm) Then txtAdd1.Focus() 37 IsValidForm = False 38 End If 39 40 If (txtCity.Text = "") Then 41 ReturnString.Append(", City") 42 txtCity.Attributes.Add("style", "background-color:#EBECED") 43 If (IsValidForm) Then txtCity.Focus() 44 IsValidForm = False 45 End If 46 47 If (ddlState.Text = "") Then 48 If (txtStateOther.Text = "") Then 49 ReturnString.Append(", State") 50 ddlState.Attributes.Add("style", "background-color:#EBECED") 51 If (IsValidForm) Then ddlState.Focus() 52 IsValidForm = False 53 End If 54 End If 55 56 If (txtZip.Text = "") Then 57 ReturnString.Append(", Zip") 58 txtZip.Attributes.Add("style", "background-color:#EBECED") 59 If (IsValidForm) Then txtZip.Focus() 60 IsValidForm = False 61 End If 62 63 If (ddlCountry.Text = "") Then 64 ReturnString.Append(", Country") 65 ddlCountry.Attributes.Add("style", "background-color:#EBECED") 66 If (IsValidForm) Then ddlCountry.Focus() 67 IsValidForm = False 68 End If 69 70 If (txtPhone.Text = "") Then 71 ReturnString.Append(", Phone") 72 txtPhone.Attributes.Add("style", "background-color:#EBECED") 73 If (IsValidForm) Then txtPhone.Focus() 74 IsValidForm = False 75 End If 76 77 MyReturn.IsValid = IsValidForm 78 79 If (ReturnString.ToString.StartsWith(",")) Then 80 MyReturn.FormFields = ReturnString.ToString.Substring(1) 81 Else 82 MyReturn.FormFields = ReturnString.ToString 83 End If 84 85 Return MyReturn 86 87 End Function
You need to create an account or log in to post comments to this site.