Sunday, June 26, 2011

Regular Expression validations

Overview

It's easy to add validation rules based on regular expressions, with SFS tools is even easier, because it automatically generates the necessary code only sets the rule as a custom property.

Prerequisites

  1. Build the sample application
  2. Understanding the extensibility of the configuration for code generation

Steps

  1. Create a file for configure the generate the generation code if the entity “Contact” (How to set up an entity for code generation)
    image 
  2. You can leave only the XML of property to customize and delete the other properties in the extensibility file.
    image
  3. Add the custom property “RegularExpression” and the validation rule: “\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*”.
    image
  4. This is the file:
    <?xml version="1.0" encoding="utf-8"?>
    <SfsModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Entities>
    <Entity Name="Contact" SetName="Contacts" IsUIVisible="false" GenerateCRUD="true" IsForLocalization="false" IsCustom="false" IsView="false" DefaultProperty="Title">
    <Properties>
    <Property Name="EmailAddress" Nullable="true" Order="100.0000" UIRequired="false" Visible="true" VisibleInGrid="true" VisibleInForm="true" PerformanceOption="Fill" IsNavigationProperty="false" Type="String" MaxLength="50" IsPrimaryKey="false" IsForeignKey="false" IsIdentity="false" IsSearchable="false" IsLocalizable="false" IsDataMember="false" IsCustom="false">
    <CustomProperties>
    <CustomProperty Name="RegularExpression" Value="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"/>
    </CustomProperties>
    </Property>
    </Properties>
    </Entity>
    </Entities>
    <Components />
    </SfsModel>

  5. regenerate the code of the user interface and build the application (SFS.AdventureWorks.Web.Mvc).
  6. Test the field validation, go to “SFS.AdventureWorks / Catalogos / Contacts” in the browser and click in “Agregar” button  (sorry by the language).
    image

 


Conclusion


The custom properties  allow you to easily add validation rules with regular expression, but you can also  add more complex rules, see the following tutorials…

No comments:

Post a Comment