Beispiel #1
0
        /// <summary>
        /// Checks if a string value is a valid CNPJ representation.
        /// </summary>
        /// <param name="value">a CNPJ string to be checked.</param>
        /// <param name="punctuation">the punctuation setting to
        /// how validation must be handled.</param>
        /// <returns>true if CNPJ string is valid; false otherwise.</returns>
        internal static bool Validate(string value, CepPunctuation punctuation)
        {
            if (StringHelper.IsNullOrWhiteSpace(value))
            {
                return(false);
            }

            if (!Regex.IsMatch(value, CepHelper.regexValidations[punctuation]))
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Checks if a string value is a valid CNPJ representation
        /// </summary>
        /// <param name="value">a CNPJ string to be checked</param>
        /// <param name="punctuation">the punctuation setting to 
        /// how validation must be handled</param>
        /// <returns>true if CNPJ string is valid; false otherwise</returns>
        internal static bool Validate(string value, CepPunctuation punctuation)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return false;
            }

            if (!Regex.IsMatch(value, CepHelper.regexValidations[punctuation]))
            {
                return false;
            }

            return true;
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Cep"/> class.
        /// </summary>
        /// <param name="value">a valid CEP string.</param>
        /// <param name="punctuation">the punctuation setting to
        /// how validation must be handled.</param>
        public Cep(string value, CepPunctuation punctuation)
        {
            if (StringHelper.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentException("O CEP não pode ser nulo ou branco");
            }

            if (!CepHelper.Validate(value, punctuation))
            {
                throw new ArgumentException("O CEP não é válido");
            }

            this.Punctuation = punctuation;
        }
Beispiel #4
0
 /// <summary>
 /// Checks if a string value is a valid CEP representation
 /// </summary>
 /// <param name="value">a CEP string to be checked</param>
 /// <param name="punctuation">the punctuation setting to
 /// how validation must be handled</param>
 /// <returns>true if CEP string is valid; otherwise, false</returns>
 public static bool Validate(string value, CepPunctuation punctuation)
 {
     return(CepHelper.Validate(value, punctuation));
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the CepAttribute class.
 /// </summary>
 /// <param name="errorMessage">The error message to associate with a validation control if validation fails.</param>
 /// <param name="punctuation">Indicates how punctuation will be handled.</param>
 public CepAttribute(string errorMessage, CepPunctuation punctuation)
     : base(errorMessage)
 {
     this.punctuation = punctuation;
 }