validation block : Binding rule set to TextBox.Text ?

Topics: Validation Application Block
Jan 30, 2009 at 8:03 PM
Edited Feb 1, 2009 at 2:05 AM

Hello everybody !!!

Sorry for my mistakes I’m not a native speaker.

I’m a very young developer and I’m working with a validation block in a windows form (VB.NET).

What I want to create are different rule set to apply to the property Text of a TextBox.

I have created those rules on a TextBox with the Enterprise Library Configuration (Designer).

I saved them into a config file (XML).

 

 

I read the documentation and I saw examples with a class. But I don’t know how to adapt it in my case study: Property Text of a TextBox.

<configuration>

  <configSections>

    <section name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

  </configSections>

  <validation>

    <type assemblyName="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"<      name="System.Windows.Forms.TextBox">

      <ruleset name="Rule Set TextBox">

        <properties>

          <property name="Text">

            <validator lowerBound="1" lowerBoundType="Inclusive" upperBound="30"

              upperBoundType="Inclusive" negated="false" messageTemplate="Maximum 30 caractères"

              messageTemplateResourceName="" messageTemplateResourceType=""

              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Length 30 Validator" />

            <validator lowerBound="4" lowerBoundType="Inclusive" upperBound="4"

              upperBoundType="Inclusive" negated="false" messageTemplate="Tapez un code comme 1000"

              messageTemplateResourceName="" messageTemplateResourceType=""

              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Code Postal Belge Length Validator" />

            <validator lowerBound="6" lowerBoundType="Ignore" upperBound="50"

              upperBoundType="Inclusive" negated="false" messageTemplate="Entre 6 et 50 caractères"

              messageTemplateResourceName="" messageTemplateResourceType=""

              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Mot de passe Length Validator" />

            <validator lowerBound="5" lowerBoundType="Inclusive" upperBound="50"

              upperBoundType="Inclusive" negated="false" messageTemplate="Entre 5 et 50 caractères"

              messageTemplateResourceName="" messageTemplateResourceType=""

              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Login Length Validator" />

            <validator pattern="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

              options="None" patternResourceName="" patternResourceType=""

              messageTemplate="Email incorrect" messageTemplateResourceName=""

              messageTemplateResourceType="" tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RegexValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Email Regex Validator" />

            <validator lowerBound="1900-01-01" lowerBoundType="Inclusive"

              upperBound="2009-01-29" upperBoundType="Inclusive" negated="false"

              messageTemplate="Date de naissance incorrecte" messageTemplateResourceName=""

              messageTemplateResourceType="" tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.DateTimeRangeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Date naissance Range Validator" />

            <validator characterSet="²³&amp;|@&quot;#'(§^!{})°-_¨[]$*%´`£€&lt;&gt;\,?.;/:+=~"

              containsCharacter="Any" negated="true" messageTemplate="Caractères spéciaux invalides"

              messageTemplateResourceName="" messageTemplateResourceType=""

              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.ContainsCharactersValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Caracteres Invalides Validator" />

            <validator characterSet="²³&amp;|@&quot;#'(§^!{})°-_¨[]$*%´`£€&lt;&gt;\?.;/:+=~"

              containsCharacter="Any" negated="true" messageTemplate="Caractères spéciaux invalides"

              messageTemplateResourceName="" messageTemplateResourceType=""

              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.ContainsCharactersValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Nbr Decimal Validator" />

            <validator characterSet="²³&amp;|@&quot;#'(§^!{})_¨[]$*%´`£€&lt;&gt;\?.;:+=~"

              containsCharacter="Any" negated="true" messageTemplate="Caractères spéciaux invalides"

              messageTemplateResourceName="" messageTemplateResourceType=""

              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.ContainsCharactersValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Bte Validator" />

            <validator characterSet="²³&amp;|@&quot;#'(§^!{})°-_¨[]$*%´`£€&lt;&gt;\,?.;/:+=~azertyuiopqsdfghjklmwxcvbn"

              containsCharacter="Any" negated="true" messageTemplate="Caractères spéciaux invalides"

              messageTemplateResourceName="" messageTemplateResourceType=""

              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.ContainsCharactersValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Code Postal Belge Validator" />

            <validator characterSet="²³|@&quot;#(§^!{})°¨[]$*%´`£€&lt;&gt;\,?;/:+=~"

              containsCharacter="Any" negated="true" messageTemplate="Caractères spéciaux invalides"

              messageTemplateResourceName="" messageTemplateResourceType=""

              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.ContainsCharactersValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

              name="Nom Prenom Validator" />

          </property>

        </properties>

      </ruleset>

    </type>

  </validation>

</configuration>

I read the documentation and I saw examples with a class. But I don’t know how to adapt it in my case study: Property Text of a TextBox

How to add a rule set  (‘Rule Set TextBox’ by example) to a TextBox (‘textbox_email’ by example)?

How to add the message(s) template(s) to a label (‘label_error_email’ by example)?
<o:p></o:p>

<o:p>
 
</o:p>

Feb 2, 2009 at 5:28 AM
You can use the ValidationProvider for validation integration with winforms.  You can use it by right clicking on the toolbox, select Choose Items, browse for the Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms dll in your EntLib installation folder.  It has a RuleSetName and ValidationResult properties which you can configure.  Upon dragging it, your winforms control will automatically have additional properties which you can see in the Validation section of your Properties window.  Check out the quickstart for validation for winforms, it uses the ValidationProvider.  Feel free to ask if you find any trouble with it.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com



Feb 2, 2009 at 8:14 PM

Hello Sarah Urmeneta.

I followed your procedure step by step and I added the ValidationProvider, every reference in my project, and

 

Imports

Microsoft.Practices.EnterpriseLibrary.Validation

 

Imports

Microsoft.Practices.EnterpriseLibrary.Validation.Validators

I saw new properties. Everything is ok.
I have my xml file built with Enterprise Library Configuration with the rules that I want to integrate to my project.
Most controls I have to validate are textbox, that's the reason I added (in the 'designer') a new : Validation Application Block - TextBox - Rule_Set_TextBox1 - Text -Validator1 ...

I just want to keep my work without rebuilding it in code-behind, is it possible ???

Feb 3, 2009 at 1:40 AM
Hi,

Is your concern is like, if you change something in your xml file that you'll need to rebuild the application? If that is the case, you dont have to rebuild the app.


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com