Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / Components / Validator / Castle.Components.Validator / Attributes / ValidateCreditCardAttribute.cs
blob3497be1e982d125214fae5ca2815af3b27e77c3b
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Components.Validator
17 using System;
19 /// <summary>
20 /// Properties decorated with this attribute will be validated to ensure that they represent a valid
21 /// credit card number.
22 /// <see ref="CreditCardValidator"/> for more details.
23 /// </summary>
24 [Serializable, CLSCompliant(false)]
25 public class ValidateCreditCardAttribute : AbstractValidationAttribute
27 private readonly IValidator validator;
29 /// <summary>
30 /// Initializes a new credit card validator.
31 /// </summary>
32 public ValidateCreditCardAttribute()
34 validator = new CreditCardValidator();
37 /// <summary>
38 /// Initializes a new credit card validator.
39 /// </summary>
40 public ValidateCreditCardAttribute(String errorMessage)
41 : base (errorMessage)
43 validator = new CreditCardValidator();
46 /// <summary>
47 /// Initializes a new credit card validator.
48 /// </summary>
49 /// <param name="allowedTypes">The card types to accept.</param>
50 public ValidateCreditCardAttribute(CreditCardValidator.CardType allowedTypes)
52 validator = new CreditCardValidator(allowedTypes);
55 /// <summary>
56 /// Initializes a new credit card validator.
57 /// </summary>
58 /// <param name="allowedTypes">The card types to accept.</param>
59 /// <param name="errorMessage">The error message to be displayed if the validation fails.</param>
60 public ValidateCreditCardAttribute(CreditCardValidator.CardType allowedTypes, String errorMessage)
61 : base(errorMessage)
63 validator = new CreditCardValidator(allowedTypes);
66 /// <summary>
67 /// Initializes a new credit card validator.
68 /// </summary>
69 /// <param name="exceptions">An array of card numbers to skip checking for (eg. gateway test numbers). Only digits should be provided for the exceptions.</param>
70 public ValidateCreditCardAttribute(string[] exceptions)
72 validator = new CreditCardValidator(exceptions);
75 /// <summary>
76 /// Initializes a new credit card validator.
77 /// </summary>
78 /// <param name="exceptions">An array of card numbers to skip checking for (eg. gateway test numbers). Only digits should be provided for the exceptions.</param>
79 /// <param name="errorMessage">The error message to be displayed if the validation fails.</param>
80 public ValidateCreditCardAttribute(string[] exceptions, String errorMessage)
81 : base(errorMessage)
83 validator = new CreditCardValidator(exceptions);
86 /// <summary>
87 /// Initializes a new credit card validator.
88 /// </summary>
89 /// <param name="allowedTypes">The card types to accept.</param>
90 /// <param name="exceptions">An array of card numbers to skip checking for (eg. gateway test numbers). Only digits should be provided for the exceptions.</param>
91 public ValidateCreditCardAttribute(CreditCardValidator.CardType allowedTypes, string[] exceptions)
93 validator = new CreditCardValidator(allowedTypes, exceptions);
96 /// <summary>
97 /// Initializes a new credit card validator.
98 /// </summary>
99 /// <param name="allowedTypes">The card types to accept.</param>
100 /// <param name="exceptions">An array of card numbers to skip checking for (eg. gateway test numbers). Only digits should be provided for the exceptions.</param>
101 /// <param name="errorMessage">The error message to be displayed if the validation fails.</param>
102 public ValidateCreditCardAttribute(CreditCardValidator.CardType allowedTypes, string[] exceptions, String errorMessage)
103 : base(errorMessage)
105 validator = new CreditCardValidator(allowedTypes, exceptions);
108 /// <summary>
109 /// Constructs and configures an <see cref="IValidator"/>
110 /// instance based on the properties set on the attribute instance.
111 /// </summary>
112 /// <returns></returns>
113 public override IValidator Build()
115 ConfigureValidatorMessage(validator);
117 return validator;