#region
public class RuleViolation
{
public string ErrorMessage
{
get;
private set;
}
public string PropertyName
{
get;
private set;
}
public RuleViolation(string errorMessage)
{
ErrorMessage = errorMessage;
}
public RuleViolation(string errorMessage, string propertyName)
{
ErrorMessage = errorMessage;
PropertyName = propertyName;
}
}
//-------------------------------------------------//
//class represent the phone validation
#region
public class PhoneValidator
{
static IDictionary
{
{"IN",new Regex("^[0-9]+$")},
{"USA",new Regex("^[2-9]\\d{2}-\\d{3}-\\d{4}$")},
{"Netherlands",new Regex("(^\\+[0-9]{2}|^\\+[0-9]{2}\\(0\\)|^\\(\\+[0-9]{2}\\)\\(0\\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\\-\\s]{10}$)")}
};
public static bool IsValidNumber(string phoneNumber, string country)
{
if (country != null && countryRegx.ContainsKey(country))
return countryRegx[country].IsMatch(phoneNumber);
else
return false;
}
public static IEnumerable
{
get { return countryRegx.Keys; }
}
}
No comments:
Post a Comment