private static bool ValidateTitleCase(DataItemBase item, bool required) { if (required && !ValidateRequired(item)) { return(false); } // We always strip line breaks var value = item.DataControl.GetValue(); value = value.Replace(" \r\n", " "); value = value.Replace("\r\n ", " "); value = value.Replace("\r\n", " "); value = value.Replace(" \r", " "); value = value.Replace("\r ", " "); value = value.Replace("\r", " "); value = value.Replace(" \n", " "); value = value.Replace("\n ", " "); value = value.Replace("\n", " "); value = value.StripRedundantSpaces(); // We only recase if it's all upper to begin with if (value.IsAllUpperCase()) { value = value.ToTitleCase(); item.AddWarning("recased"); } item.DataControl.SetValue(value); return(true); }
protected static bool ValidateMiddleName(DataItemBase item) { item.StripRedundantWhiteSpace(); item.DataControl.SetValue( Validation.FixGivenName(item.DataControl.GetValue())); return(true); }
protected static bool ValidateCityStateZip(DataItemBase item) { item.StripRedundantWhiteSpace(); item.DataControl.SetValue( Validation.FixCityStateZip(item.DataControl.GetValue())); return(true); }
protected static bool ValidateEmailRequired(DataItemBase item) { if (!ValidateRequired(item)) { return(false); } return(ValidateEmail(item)); }
protected static bool ValidateDateOfBirth(DataItemBase item) { if (!ValidateRequired(item)) { return(false); } return(ValidateDateOfBirthOptional(item)); }
protected static bool ValidateYouTubeAddressRequired(DataItemBase item) { if (!ValidateRequired(item)) { return(false); } return(ValidateYouTubeAddressOptional(item)); }
protected static bool ValidateWebAddressRequired(DataItemBase item) { if (!ValidateRequired(item)) { return(false); } item.DataControl.SetValue( Validation.StripWebProtocol(item.DataControl.GetValue())); return(true); }
protected static bool ValidateDateOptional(DataItemBase item) { var validated = item.Feedback.ValidateDateOptional(item.DataControl as TextBox, out var success, item.Description, VotePage.DefaultDbDate); if (success) { item.DataControl.SetValue(ToDisplayDate(validated)); } return(success); }
public static bool ValidateRequired(DataItemBase item) { item.StripRedundantWhiteSpace(); var value = item.Feedback.ValidateRequired(item.DataControl, item.Description, out var success); if (success) { item.DataControl.SetValue(ToDisplay(value)); } return(success); }
protected static bool ValidateSignedNumeric(DataItemBase item) { var value = item.DataControl.GetValue().Trim(); if (!Regex.IsMatch(value, @"^(?:\+|-)?[0-9]+$")) { item.Feedback.PostValidationError(item.DataControl, "A numeric value is required"); return(false); } item.DataControl.SetValue(value); return(true); }
protected static bool ValidateNumeric(DataItemBase item) { var value = item.DataControl.GetValue().Trim(); if (!value.IsDigits()) { item.Feedback.PostValidationError(item.DataControl, "A numeric value is required"); return(false); } item.DataControl.SetValue(value); return(true); }
protected static bool ValidateFirstName(DataItemBase item) { item.StripRedundantWhiteSpace(); item.Feedback.ValidateRequired(item.DataControl, item.Description, out var success); if (!success) { return(false); } item.DataControl.SetValue( Validation.FixGivenName(item.DataControl.GetValue())); return(true); }
protected static bool ValidateSuffix(DataItemBase item) { item.StripRedundantWhiteSpace(); var value = item.DataControl.GetValue(); if (!Validation.IsValidNameSuffix(value)) { item.Feedback.PostValidationError(item.DataControl, "We do not recognize the Suffix as valid"); return(false); } item.DataControl.SetValue(Validation.FixNameSuffix(value)); return(true); }
protected static bool ValidateDateOfBirthOptional(DataItemBase item) { var now = DateTime.UtcNow; var min = now - new TimeSpan(36525, 0, 0, 0); // 100 years var max = now - new TimeSpan(6575, 0, 0, 0); // 18 years var validated = item.Feedback.ValidateDateOptional(item.DataControl as TextBox, out var success, item.Description, min, max, VotePage.DefaultDbDate); if (success) { item.DataControl.SetValue( Politicians.GetDateOfBirthFromDateTime(validated)); } return(success); }
protected static bool ValidateMoneyOptional(DataItemBase item) { item.StripRedundantWhiteSpace(); var value = item.DataControl.GetValue(); if (IsNullOrWhiteSpace(value)) { return(true); } if (!decimal.TryParse(value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var d)) { item.Feedback.PostValidationError(item.DataControl, "A dollar value is required"); return(false); } item.DataControl.SetValue(d == 0 ? Empty : d.ToString("0.00")); return(true); }
protected static bool ValidateEmail(DataItemBase item) { item.StripRedundantWhiteSpace(); var value = item.DataControl.GetValue(); if (value.StartsWith("mailto:", StringComparison.OrdinalIgnoreCase)) { value = value.Substring(7); } if (!IsNullOrWhiteSpace(value) && !Validation.IsValidEmailAddress(value)) { item.Feedback.PostValidationError(item.DataControl, "We do not recognize the Email as valid"); return(false); } item.DataControl.SetValue(Validation.StripWebProtocol(value)); return(true); }
protected static bool ValidateLastName(DataItemBase item) { bool success; item.StripRedundantWhiteSpace(); item.Feedback.ValidateRequired(item.DataControl, item.Description, out success); if (!success) { return(false); } var value = item.DataControl.GetValue(); if (!Validation.IsValidLastName(value)) { item.Feedback.PostValidationError(item.DataControl, "We do not recognize the Last Name as valid"); return(false); } var tokens = value.Trim() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length >= 2) { if (char.IsLetter(tokens[0][0]) && (tokens[0][1] == '.')) { item.Feedback.PostValidationError(item.DataControl, "Please use the Middle or Initial field for initials"); return(false); } if (Validation.IsValidNameSuffix(tokens[tokens.Length - 1])) { item.Feedback.PostValidationError(item.DataControl, "Please use the Suffix field for " + tokens[tokens.Length - 1]); return(false); } } item.DataControl.SetValue(Validation.FixLastName(value)); return(true); }
private static bool ValidateTitleCase(DataItemBase item, bool required) { if (required && !ValidateRequired(item)) { return(false); } // We always strip line breaks var value = Regex.Replace(item.DataControl.GetValue(), @"[\r\n]+", " ").StripRedundantSpaces(); // We only recase if it's single case to begin with if (!value.IsMixedCase()) { value = value.ToTitleCase(); item.AddWarning("recased"); } item.DataControl.SetValue(value); return(true); }
private static bool ValidateSentenceCase(DataItemBase item, bool required) { if (required && !ValidateRequired(item)) { return(false); } var value = item.DataControl.GetValue(); value = value.StripRedundantSpaces(); // We only recase if it's all upper to begin with if (value.IsAllUpperCase()) { value = value.ToSentenceCase(); item.AddWarning("recased"); } item.DataControl.SetValue(value); return(true); }
protected static bool ValidateYouTubeVideoAddressOptional(DataItemBase item) { string message = null; var value = item.DataControl.GetValue(); if (!IsNullOrWhiteSpace(value)) { if (value.IsValidYouTubeVideoUrl()) { var id = value.GetYouTubeVideoId(); var info = YouTubeVideoUtility.GetVideoInfo(id, true, 1); if (!info.IsValid) { message = YouTubeVideoInfo.VideoIdNotFoundMessage; } else if (!info.IsPublic) { message = YouTubeVideoInfo.VideoNotPublicMessage; } } else { message = "The URL is not a valid YouTube video URL"; } } if (IsNullOrWhiteSpace(message)) { item.DataControl.SetValue( Validation.StripWebProtocol(value)); } else { item.Feedback.PostValidationError(item.DataControl, message); } return(IsNullOrWhiteSpace(message)); }
internal static int Update(this IEnumerable <DataItemBase> items, FeedbackContainerControl feedback, bool showSummary = true, UpdatePanel updatePanel = null) { return(DataItemBase.UpdateAll(items, feedback, showSummary, updatePanel)); }
protected static bool ValidateYouTubeAddressOptional(DataItemBase item) { string message = null; var value = item.DataControl.GetValue(); if (!IsNullOrWhiteSpace(value)) { if (value.IsValidYouTubeVideoUrl()) { var id = value.GetYouTubeVideoId(); var info = YouTubeVideoUtility.GetVideoInfo(id, true, 1); if (!info.IsValid) { message = YouTubeVideoInfo.VideoIdNotFoundMessage; } else if (!info.IsPublic) { message = YouTubeVideoInfo.VideoNotPublicMessage; } } else if (value.IsValidYouTubePlaylistUrl()) { var id = value.GetYouTubePlaylistId(); var info = YouTubeVideoUtility.GetPlaylistInfo(id, true, 1); if (!info.IsValid) { message = YouTubeVideoInfo.PlaylistIdNotFoundMessage; } else if (!info.IsPublic) { message = YouTubeVideoInfo.PlaylistNotPublicMessage; } } else if (value.IsValidYouTubeChannelUrl() || value.IsValidYouTubeCustomChannelUrl() || value.IsValidYouTubeUserChannelUrl()) { var id = YouTubeVideoUtility.LookupChannelId(value, 1); if (IsNullOrWhiteSpace(id)) { message = YouTubeVideoInfo.ChannelIdNotFoundMessage; } else { var info = YouTubeVideoUtility.GetChannelInfo(id, true, 1); if (!info.IsValid) { message = YouTubeVideoInfo.ChannelIdNotFoundMessage; } else if (!info.IsPublic) { message = YouTubeVideoInfo.ChannelNotPublicMessage; } } } else { message = "The URL is not a valid YouTube channel, playlist or video URL"; } } if (IsNullOrWhiteSpace(message)) { item.DataControl.SetValue( Validation.StripWebProtocol(value)); } else { item.Feedback.PostValidationError(item.DataControl, message); } return(IsNullOrWhiteSpace(message)); }
internal static bool Validate(this IEnumerable <DataItemBase> items) { return(DataItemBase.ValidateAll(items)); }
protected static bool ValidateWebAddress(DataItemBase item) { item.DataControl.SetValue( Validation.StripWebProtocol(item.DataControl.GetValue())); return(true); }
protected static bool ValidateTitleCaseRequired(DataItemBase item) { return(ValidateTitleCase(item, true)); }
protected static bool ValidateTitleCase(DataItemBase item) { return(ValidateTitleCase(item, false)); }
protected static bool ValidateWhiteSpace(DataItemBase item) { item.StripRedundantWhiteSpace(); return(true); }
internal static IEnumerable <DataItemBase> WithWarning(this IEnumerable <DataItemBase> items, string warning) { return(DataItemBase.WithWarning(items, warning)); }
protected static bool ValidateStreet(DataItemBase item) { item.StripRedundantWhiteSpace(); item.DataControl.SetValue(Validation.FixAddress(item.DataControl.GetValue())); return(true); }
public static string GetCurrentValue(DataItemBase item) { return(item.GetCurrentValue()); }