Add validation to XForms textbox

by: Jacob Khan

 

I recently came across a partner that needed to add custom validation in the Editor making it possible to validate for such things as emails ending with .dk are not allowed.

After some failure in digging around I went to the back-end team and asked Paul Smith and Per Gunsarfs who had the answer I was looking for.

Here some code to add your own little XForms validation:

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Linq;
   4: using System.Web;
   5:  
   6: namespace EPiServer
   7: {
   8:     public class XformsStuff : EPiServer.PlugIn.PlugInAttribute
   9:     {
  10:         public static void Start()
  11:         {
  12:             EPiServer.XForms.DataTypes.Types.Add("specialemail", "my awesome regexp");
  13:  
  14:         }
  15:     }
  16: }

 

Here is what it looks live in the XForms editor

image

28 July 2009

Tags:


    Comments

    1. I wonder why that regexp isn't included by default? :)
    2. Great snippet. Re-comment Peter :)
    3. Hi Jacob, Could this be extended to validate that two text fields in the form were equal. ie: one field to enter email address (email) and a second to enter email address again to confirm (emailConfirm). I want to validate that both text fields are the same – (email = emailConfirm) Cheers, Linda
    4. bb
    Post a comment    
    User verification Image for user verification  
    Jacob Khan

    About me

    I am a researcher at EPiServer based in Stockholm. I started working in the Research department in May 2008.
    I also blog on world.episerver.com
    See my profile card on world

     

    Syndications


    Archive


    Tag cloud

    EPiTrace logger