<abc:RegularExpressionValidator runat="server" ControlToValidate="uxRequestorEmailTextBox" Entity="Requestor's Email" Type="EmailAddress" />
Imports Microsoft.VisualBasic Imports System.Web.UI.WebControls Namespace AcmeBroomCompany Public Enum RegExFieldType NotSet PhoneNumber EmailAddress 'SocialSecurityNumber 'DateMmDdYyyy End Enum Public Class RegularExpressionValidator Inherits System.Web.UI.WebControls.RegularExpressionValidator Private _type As RegExFieldType Private _entity As String Public Sub New() Display = ValidatorDisplay.Dynamic EnableClientScript = True SetFocusOnError = True Text = "" Dim img As Image = New Image() img.ImageUrl = "~/images/Exclamation.png" Me.Controls.Add(img) _entity = "" End Sub Public Property Entity() As String Get Return _entity End Get Set(ByVal value As String) _entity = value UpdateErrorMessage() End Set End Property Public Property Type() As RegExFieldType Get Return _type End Get Set(ByVal value As RegExFieldType) _type = value UpdateErrorMessage() UpdateRegEx() End Set End Property Private Sub UpdateRegEx() Dim s As String = "" Select Case _type Case RegExFieldType.PhoneNumber s = "^[2-9]\d{2}\-\d{3}\-\d{4}$" Case RegExFieldType.EmailAddress s = "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}" 'Case RegExFieldType.DateMmDdYyyy 'Case RegExFieldType.SocialSecurityNumber End Select Me.ValidationExpression = s End Sub Private Sub UpdateErrorMessage() Dim entityType As String = "" Select Case _type Case RegExFieldType.PhoneNumber entityType = "phone number" Case RegExFieldType.EmailAddress entityType = "email address" End Select If entityType.Length = 0 Then ErrorMessage = _entity & " is an invalid form for the field." Else ErrorMessage = _entity & " must be a valid " + entityType & "." End If End Sub End Class End Namespace
TODO
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.