1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
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.
24 [Serializable
, CLSCompliant(false)]
25 public class ValidateCreditCardAttribute
: AbstractValidationAttribute
27 private readonly IValidator validator
;
30 /// Initializes a new credit card validator.
32 public ValidateCreditCardAttribute()
34 validator
= new CreditCardValidator();
38 /// Initializes a new credit card validator.
40 public ValidateCreditCardAttribute(String errorMessage
)
43 validator
= new CreditCardValidator();
47 /// Initializes a new credit card validator.
49 /// <param name="allowedTypes">The card types to accept.</param>
50 public ValidateCreditCardAttribute(CreditCardValidator
.CardType allowedTypes
)
52 validator
= new CreditCardValidator(allowedTypes
);
56 /// Initializes a new credit card validator.
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
)
63 validator
= new CreditCardValidator(allowedTypes
);
67 /// Initializes a new credit card validator.
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
);
76 /// Initializes a new credit card validator.
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
)
83 validator
= new CreditCardValidator(exceptions
);
87 /// Initializes a new credit card validator.
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
);
97 /// Initializes a new credit card validator.
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
)
105 validator
= new CreditCardValidator(allowedTypes
, exceptions
);
109 /// Constructs and configures an <see cref="IValidator"/>
110 /// instance based on the properties set on the attribute instance.
112 /// <returns></returns>
113 public override IValidator
Build()
115 ConfigureValidatorMessage(validator
);