示例#1
0
        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);
        }
示例#2
0
 protected static bool ValidateMiddleName(DataItemBase item)
 {
     item.StripRedundantWhiteSpace();
     item.DataControl.SetValue(
         Validation.FixGivenName(item.DataControl.GetValue()));
     return(true);
 }
示例#3
0
 protected static bool ValidateCityStateZip(DataItemBase item)
 {
     item.StripRedundantWhiteSpace();
     item.DataControl.SetValue(
         Validation.FixCityStateZip(item.DataControl.GetValue()));
     return(true);
 }
示例#4
0
 protected static bool ValidateEmailRequired(DataItemBase item)
 {
     if (!ValidateRequired(item))
     {
         return(false);
     }
     return(ValidateEmail(item));
 }
示例#5
0
 protected static bool ValidateDateOfBirth(DataItemBase item)
 {
     if (!ValidateRequired(item))
     {
         return(false);
     }
     return(ValidateDateOfBirthOptional(item));
 }
示例#6
0
 protected static bool ValidateYouTubeAddressRequired(DataItemBase item)
 {
     if (!ValidateRequired(item))
     {
         return(false);
     }
     return(ValidateYouTubeAddressOptional(item));
 }
示例#7
0
 protected static bool ValidateWebAddressRequired(DataItemBase item)
 {
     if (!ValidateRequired(item))
     {
         return(false);
     }
     item.DataControl.SetValue(
         Validation.StripWebProtocol(item.DataControl.GetValue()));
     return(true);
 }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
 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);
 }
示例#13
0
        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);
        }
示例#14
0
        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);
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        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);
        }
示例#18
0
        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);
        }
示例#19
0
        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);
        }
示例#20
0
        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));
        }
示例#21
0
 internal static int Update(this IEnumerable <DataItemBase> items,
                            FeedbackContainerControl feedback, bool showSummary = true,
                            UpdatePanel updatePanel = null)
 {
     return(DataItemBase.UpdateAll(items, feedback, showSummary, updatePanel));
 }
示例#22
0
        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));
        }
示例#23
0
 internal static bool Validate(this IEnumerable <DataItemBase> items)
 {
     return(DataItemBase.ValidateAll(items));
 }
示例#24
0
 protected static bool ValidateWebAddress(DataItemBase item)
 {
     item.DataControl.SetValue(
         Validation.StripWebProtocol(item.DataControl.GetValue()));
     return(true);
 }
示例#25
0
 protected static bool ValidateTitleCaseRequired(DataItemBase item)
 {
     return(ValidateTitleCase(item, true));
 }
示例#26
0
 protected static bool ValidateTitleCase(DataItemBase item)
 {
     return(ValidateTitleCase(item, false));
 }
示例#27
0
 protected static bool ValidateWhiteSpace(DataItemBase item)
 {
     item.StripRedundantWhiteSpace();
     return(true);
 }
示例#28
0
 internal static IEnumerable <DataItemBase> WithWarning(this IEnumerable <DataItemBase> items,
                                                        string warning)
 {
     return(DataItemBase.WithWarning(items, warning));
 }
示例#29
0
 protected static bool ValidateStreet(DataItemBase item)
 {
     item.StripRedundantWhiteSpace();
     item.DataControl.SetValue(Validation.FixAddress(item.DataControl.GetValue()));
     return(true);
 }
示例#30
0
 public static string GetCurrentValue(DataItemBase item)
 {
     return(item.GetCurrentValue());
 }