private void SpecialFormatCheck(string i_Input, ParseValidity i_Format) { switch (i_Format) { case ParseValidity.LicencePlate: if (Regex.IsMatch(i_Input, @"^[a-zA-Z0-9]+$") == false) { throw new FormatException("Licence plate must contain digits and/or letters only"); } break; case ParseValidity.ClientName: if (Regex.IsMatch(i_Input, @"^[a-zA-Z]+$") == false) { throw new FormatException("Client's name must contain letters only"); } break; case ParseValidity.ClientPhone: if (Regex.IsMatch(i_Input, @"^[0-9]+$") == false) { throw new FormatException("Client's phone must contain digits only"); } break; } }
private bool CallToSpecialFormatCheck(string i_Input, int i_Length, ParseValidity i_Format) { bool returnStatement = true; try { CheckLengthAndSpecialFormatValidity(i_Input, i_Length, i_Format); returnStatement = false; } catch (FormatException formatEx) { Console.WriteLine(formatEx.Message); } return(returnStatement); }
private void CheckLengthAndSpecialFormatValidity(string i_Input, int i_Length, ParseValidity i_Format) { if (i_Input.Length < i_Length) { string msg = string.Format(@"The parameter must be {0} at least signs long", i_Length); throw new FormatException(msg); } SpecialFormatCheck(i_Input, i_Format); }