DomainValidator - covert everything .tolower

Topics: Validation Application Block
Mar 9, 2009 at 10:05 AM
I would like to covert all the input of a textbox to lower so i can validate it using the domainvalidator

when i type <SCRIPT> into Textbox1 and then click the Button1 it fails to validate as the DomainValidator is case senstive which only validates <script>

So i want it to convert everything that i typed in Textbox1 into lower, validate the input using the class, if it passes then continue with the "Original text from the textbox"

below is my code sample


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    End Sub

    Sub proxy_validator()

        PropertyProxyValidator1.ControlToValidate = "Textbox1"
        PropertyProxyValidator1.PropertyName = "AccountName"
        PropertyProxyValidator1.SourceTypeName = "ss_validation"
        PropertyProxyValidator1.SpecificationSource = ValidationSpecificationSource.Both
        PropertyProxyValidator1.Display = ValidatorDisplay.None

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        If Page.IsValid Then
            Label1.Text = "success!"
            Label1.Text = "failed to validate"
        End If

    End Sub

Imports Microsoft.VisualBasic
Imports Microsoft.Practices.EnterpriseLibrary.Validation.Validators
Imports Resources

Public Class ss_validation

    Dim _AccountName As String = Nothing
    <StringLengthValidator(1, 10, MessageTemplateResourceType:=GetType(StarOne), MessageTemplateResourceName:="account_textbox_callout")> _
    <DomainValidator("<script>", "</script>", "<%", "%>", "<!", "!>", "<noscript>", "</noscript>", "<?php", "?>", MessageTemplateResourceType:=GetType(Resource), MessageTemplateResourceName:="validation_script_injection", negated:=True)> _
    Public Property AccountName() As String

            Return _AccountName
        End Get

        Set(ByVal _value As String)
            _AccountName = _value
        End Set

    End Property
End Class
Mar 9, 2009 at 11:28 AM

You can do it on the ValueConvert event of the proxyvalidator. like this : 



        protected void PropertyProxyValidator1_ValueConvert(object sender, ValueConvertEventArgs e)


            e.ConvertedValue = e.ValueToConvert.ToString().ToLower();


Where "e.ValueToConvert" contains the string that was input from the textbox.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.




Mar 9, 2009 at 12:02 PM
thanks Valiant
just what i was after!!!