Sunday, June 26, 2011

Regular Expression validations


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.


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


  1. Create a file for configure the generate the generation code if the entity “Contact” (How to set up an entity for code generation)
  2. You can leave only the XML of property to customize and delete the other properties in the extensibility file.
  3. Add the custom property “RegularExpression” and the validation rule: “\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*”.
  4. This is the file:
    <?xml version="1.0" encoding="utf-8"?>
    <SfsModel xmlns:xsi="" xmlns:xsd="">
    <Entity Name="Contact" SetName="Contacts" IsUIVisible="false" GenerateCRUD="true" IsForLocalization="false" IsCustom="false" IsView="false" DefaultProperty="Title">
    <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">
    <CustomProperty Name="RegularExpression" Value="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"/>
    <Components />

  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).



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