I was going thru a msdn tutorial and there was a property that was being validated in a class. Is the best practice to do this in a class or on the client side of a presentation layer?
I see the advantage of doing it in a class that you can reuse the code among web pages. I see the advantage of doing it on the client side of a presentation layer as faster performance.
Thanks!
I see the advantage of doing it in a class that you can reuse the code among web pages. I see the advantage of doing it on the client side of a presentation layer as faster performance.
Thanks!
Code:
public string SSN
{
get { return this.uniqueSsn; }
set {
if (Regex.IsMatch(value, @"\d{9}"))
uniqueSsn = String.Format("{0}-(1}-{2}", value.Substring(0, 3),
value.Substring(3, 2),
value.Substring(5, 3));
else if (Regex.IsMatch(value, @"\d{3}-\d{2}-\d{3}"))
uniqueSsn = value;
else
throw new FormatException("The social security number has an invalid format.");
}
}