Posted by Adam Buenz

There was a post in the newsgroups wondering how when constructing a custom field type how one might build a small generic validation function in order to verify the harvested user input. There is provided the SPField.GetValidatedString method, which is overridable, that can be used in order to achieve this since it will take the object input provided by the custom field type and provide a workable string representation.

An example of this method is this:

C#:
  1. private readonly string m_strValidationException = "Hmmm, your string length wasen't 10!";
  2.  
  3. public override string GetValidatedString(object oValue)
  4. {
  5. if (oValue.ToString().Length != 10)
  6.  
  7. {
  8. throw new SPFieldValidationException(m_strValidationException);
  9. }
  10.  
  11. else
  12.  
  13. {
  14. return oValue.ToString();
  15. }
  16.  
  17. }

2 Responses to “Custom Field Validation With SPFieldValidationException”

  1. Blogger Loser » Custom Field Validation With SPFieldValidationException Says:

    [...] There was a post in the newsgroups wondering how when constructing a custom field type how one might build a small generic validation function in order to verify the harvested user input. There is provided the SPField.GetValidatedString method, which Read More……(read more) October 13th 2007 Posted to Uncategorized [...]

  2. ThemePassion - Best stuff about design! » Custom Field Validation With SPFieldValidationException Says:

    [...] desconocido wrote an interesting post today!.Here’s a quick excerptThere was a post in the newsgroups wondering how when constructing a custom field type how one might build a small generic validation function in order to verify the harvested user input. There is provided the SPField. … [...]

Leave a Reply