private string GetValidationError(string text) { string result = null; switch (text) { case "SSN": string SSNpattern = @"^\d{3}-\d{2}-\d{4}$"; Regex reg = new Regex(SSNpattern); if (string.IsNullOrWhiteSpace(SSN)) { result = "Field cannot be empty."; } else if (!reg.IsMatch(SSN)) { result = "Invalid Social Security Number."; } else if (SSN.Length > 11) { result = "Too many characters."; } else { List <AdultBasicInfoClass> ab; using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("EnrollmentDB"))) { ab = connection.Query <AdultBasicInfoClass>($"Select * From AdultBasicInfo Where SSN != 'NULL' And Id != '{ Id }'").ToList(); foreach (var v in ab) { if (SSN.Equals(v.SSN)) { result = "An account already exists with that SSN."; break; } } } } break; case "completedEdLevel": if (string.IsNullOrWhiteSpace(completedEdLevel)) { result = "Field cannot be empty."; } break; case "attendedCollegeOrTech": if (string.IsNullOrWhiteSpace(attendedCollegeOrTech)) { result = "Field cannot be empty."; } break; case "liveWithParent": if (string.IsNullOrWhiteSpace(liveWithParent)) { result = "Field cannot be empty."; } break; case "lastName": if (string.IsNullOrWhiteSpace(lastName)) { result = "Name field cannot be empty."; } else if (lastName.Length >= 50) { result = "Too many characters."; } break; case "firstName": if (string.IsNullOrWhiteSpace(firstName)) { result = "Name field cannot be empty."; } else if (firstName.Length >= 50) { result = "Too many characters."; } break; case "middleInitial": if (middleInitial.Length > 5) { result = "Too many characters."; } break; case "program": if (string.IsNullOrWhiteSpace(program)) { result = "Please state the program you wish to attend."; } else if (program.Length >= 50) { result = "Too many characters."; } break; case "streetAddress": if (string.IsNullOrWhiteSpace(streetAddress)) { result = "Field must not be empty."; } else if (streetAddress.Length >= 50) { result = "Too many characters."; } break; case "city": if (string.IsNullOrWhiteSpace(city)) { result = "Field must not be empty."; } else if (city.Length >= 50) { result = "Too many characters."; } break; case "state": if (string.IsNullOrWhiteSpace(state)) { result = "Field must not be empty."; } break; case "zipCode": if (string.IsNullOrWhiteSpace(zipCode)) { result = "Field must not be empty."; } else if (!CommonMethods.IsZipCode(zipCode)) { result = "Invalid ZipCode."; } break; case "primaryPhoneNum": if (string.IsNullOrWhiteSpace(primaryPhoneNum)) { result = "Field must not be empty."; } else if (!CommonMethods.IsPhoneNumber(primaryPhoneNum)) { result = "Invalid phone number."; } break; case "cellPhoneNum": if (string.IsNullOrWhiteSpace(cellPhoneNum)) { result = "Field must not be empty."; } else if (!CommonMethods.IsPhoneNumber(cellPhoneNum)) { result = "Invalid phone number."; } break; case "hispanicOrLatino": if (string.IsNullOrWhiteSpace(hispanicOrLatino)) { result = "Field must not be empty"; } break; case "race": if (string.IsNullOrWhiteSpace(race)) { result = "Field must not be empty"; } break; case "gender": if (string.IsNullOrWhiteSpace(gender)) { result = "Field must not be empty"; } break; case "dateOfBirth": if (string.IsNullOrWhiteSpace(dateOfBirth)) { result = "Select a date."; } else { int dateResult = DateTime.Compare(Convert.ToDateTime(dateOfBirth), DateTime.Now.AddYears(-14)); if (!(dateResult < 0)) { result = "Invalid date."; } dateResult = DateTime.Compare(Convert.ToDateTime(dateOfBirth), DateTime.Now.AddYears(-100)); if (dateResult < 0) { result = "Invalid date."; } } break; } return(result); }