ASP.NET MVC2 - Trim white space from form submits before server-side validation?
- by David Lively
If I add a validation attribute:
public class ProductDownloadListModel
{
//xxxxx-xxxxx-xxxxx
[Required]
[StringLength(17)]
public string PSN { get; set; }
public DateTime PsnExpirationDate { get; set; }
public DataTable Downloads { get; set; }
}
and the user enters a 17-character string but includes white space on the end, I get a validation error because the string is greater than that specified by the [StringLength(17)] attribute. How can I prevent this? I'd prefer not to have to have javaScript trim the string before submits.