-1

I have developed a customer contact form in MVC. Which a description field for 2000 characters. This is completely external facing page. So users can enter any junk data here. I have to send this data in the XML format including other fields (like first name, last name ,email adress , etc) to another system. So XML has to accept the text from this form fields.

How can I validate when user enter data, remove un-necessary data from description field. ?

James123
  • 11,184
  • 66
  • 189
  • 343
  • Define 'un-necessary data' please. – Maess Jan 23 '14 at 17:23
  • What qualifies as unnecessary data? All you have said is 2000 characters. Apart from setting a limit on number of characters you have included little else. – Gjohn Jan 23 '14 at 17:41
  • If you are trying to make the data part of a valid XML document, you will need to escape it and/or put it into a CDATA section: http://stackoverflow.com/questions/2784183/what-does-cdata-in-xml-mean – Tim M. Jan 23 '14 at 22:26

1 Answers1

0

On your property in your model set an attribute on it like so:

public class DataModel
  {
    [StringLength(2000, ErrorMessage = "Field cannot exceed 2000 characters")]
    public string Description { get; set; }
  }

That way the Users will remove their own junk if what they want to put in the field does not fit under 2000 characters.

Jason Roell
  • 6,679
  • 4
  • 21
  • 28