ASP.NET MVC2 - Trim white space from form submits before server-side validation?
Posted
by
David Lively
on Stack Overflow
See other posts from Stack Overflow
or by David Lively
Published on 2011-01-07T17:49:58Z
Indexed on
2011/01/07
17:54 UTC
Read the original article
Hit count: 180
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.
© Stack Overflow or respective owner