예제 #1
0
        static public string IsPostalCode(string value, bool required, string country)
        {
            value = (value + "").Trim();

            var saveCulture = Thread.CurrentThread.CurrentCulture;



            if (string.IsNullOrEmpty(country))
            {
                country = "US";
            }
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-" + country);
            try
            {
                if (string.IsNullOrEmpty(value))
                {
                    if (required)
                    {
                        return(ValidationMessages.Must_Have_Value(Resources.ResourceUI.ZipCode));
                    }
                    return(null);
                }

                if (value.Length > 10)
                {
                    return(ValidationMessages.Postalcode_Invalid_Format(Resources.ResourceUI.ZipCode));
                }

                Regex pattern = new Regex(Resources.ResourceUI.ZipCodeRegEx);

                if (!pattern.IsMatch(value.Trim()))
                {
                    return(ValidationMessages.Postalcode_Invalid_Format(Resources.ResourceUI.ZipCode));
                }

                return(null);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = saveCulture;
            }
        }
예제 #2
0
        static public bool IsWholeNumber(Messages messages, string value, string propertyName, string desc, bool required)
        {
            if (string.IsNullOrEmpty(value))
            {
                if (required)
                {
                    messages.AddError(propertyName, ValidationMessages.Must_Have_Value(desc));
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            if (!IsWholeNumber(value))
            {
                messages.AddError(propertyName, ValidationMessages.Number_Invalid_Format(desc));
                return(false);
            }

            return(true);
        }
예제 #3
0
        static public bool IsInDateRange(Messages messages, DateTime?value, string propertyName, string desc, DateTime from, DateTime to, bool required)
        {
            if (!value.HasValue)
            {
                if (required)
                {
                    messages.AddError(propertyName, ValidationMessages.Must_Have_Value(desc));
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            if (value.HasValue && (value.Value < from || value.Value > to))
            {
                messages.AddError(propertyName, ValidationMessages.Date_Out_Of_Range(desc, from, to));
                return(false);
            }

            return(true);
        }