I have 3 input boxes for someone to enter a phone number. One for the area code (3 digits), one for the prefix (3 digits), and one for the suffix(4 digits). I want to validate that the sum of the 3 fields equals 10 before saving. How can that be done using data annotations?
model:
public string PhoneNumber
{
get
{
return _phoneNumber;
}
set
{
_phoneNumber = value;
}
}
private string _phoneNumber;
public string Area
{
get
{
try
{
return _phoneNumber.Split(new char[] { '(', ')', '-' }, StringSplitOptions.RemoveEmptyEntries)[0].Trim();
}
catch
{
return "";
}
}
}
public string Prefix
{
get
{
try
{
return _phoneNumber.Split(new char[] { '(', ')', '-' }, StringSplitOptions.RemoveEmptyEntries)[1].Trim();
}
catch
{
return "";
}
}
}
public string Suffix
{
get
{
try
{
return _phoneNumber.Split(new char[] { '(', ')', '-' }, StringSplitOptions.RemoveEmptyEntries)[2].Trim();
}
catch
{
return "";
}
}
}