Im working in asp.net mvc application which was done in mvc 1... so validations were done following the nerd dinner 1.0 tutorial
I just defined a rule like this
public bool Is_CellPhone(string val)
{
Regex celular = new Regex("^04[12][246][0-9]{7}$");
return celular.IsMatch(val);
}
and in my GetRuleValidations I do this
if (!Is_CellPhone(Celular))
yield return new RuleViolation("El celular no cumple el formato",
"Celular");
The problem is.. cell phone is not required so when the user doesnt submit that value the validation method runs anyway and returns an error because of the null string... what can I do to properly prevent this error?