| Hi, You can write a regular _expression_ as shown in the example below: ' RegexDomValidator.vb Option Explicit Option Strict Imports System.ComponentModel Imports System.ComponentModel.Design Imports System.Diagnostics Imports System.Text.RegularExpressions Imports System.Drawing.Design Imports System Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Namespace DomValidators <ToolboxData("<{0}:RegexDomValidator runat=server ErrorMessage=""RegexDomValidator""></{0}:RegexDomValidator>")> _ Public Class RegexDomValidator Inherits BaseDomValidator <Bindable(True), _ Category("Behavior"), _ DefaultValue(""), _ Editor("System.Web.UI.Design.WebControls.RegexTypeEditor,System.Design", _ GetType(UITypeEditor)), _ Description("ValidationExpression")> _ Public Property ValidationExpression() As String Get Dim o As Object = ViewState("ValidationExpression") If o Is Nothing Then Return String.Empty Else Return CStr(o) End If End Get Set Try Regex.IsMatch("", value) Catch e As Exception 'Throw new HttpException. ' HttpRuntime.FormatResourceString(SR.Validator_bad_regex, value), e); Throw New HttpException("Bad _expression_", e) End Try ViewState("ValidationExpression") = value End Set End Property Protected Overrides Sub AddAttributesToRender(writer As HtmlTextWriter) MyBase.AddAttributesToRender(writer) If RenderUplevel Then writer.AddAttribute("evaluationfunction", "RegularExpressionValidatorEvaluateIsValid") If ValidationExpression.Length > 0 Then writer.AddAttribute("validationexpression", ValidationExpression) End If End If End Sub Protected Overrides Function EvaluateIsValid() As Boolean ' Always succeeds if input is empty or value was not found. Dim controlValue As String = GetControlValidationValue(ControlToValidate) Debug.Assert( Not (controlValue Is Nothing), "Should have already been checked") If controlValue Is Nothing Or controlValue.Length = 0 Then Return True End If Try ' Looking for an exact match, not just a search hit. Dim m As Match = Regex.Match(controlValue, ValidationExpression) Return m.Success And m.Index = 0 And m.Length = controlValue.Length Catch End Try End Function End Class End Namespace
In the validator _expression_, you can check for the dd/mm/yyyy format as , the value in the textbox is compared with the value of the validator _expression_. In the above code, the validator _expression_ checks for empty and null spaces. you can code it to check for date value. HTH Regards Lakshmi |