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 /// Validate that the property match the given regular expression
22 [Serializable
, CLSCompliant(false)]
23 public class ValidateRegExpAttribute
: AbstractValidationAttribute
25 private readonly string pattern
;
28 /// Initializes a new instance of the <see cref="ValidateRegExpAttribute"/> class.
30 /// <param name="pattern">The pattern.</param>
31 public ValidateRegExpAttribute(String pattern
)
33 this.pattern
= pattern
;
37 /// Initializes a new instance of the <see cref="ValidateRegExpAttribute"/> class.
39 /// <param name="pattern">The pattern.</param>
40 /// <param name="errorMessage">The error message.</param>
41 public ValidateRegExpAttribute(String pattern
, String errorMessage
) : base(errorMessage
)
43 this.pattern
= pattern
;
47 /// Constructs and configures an <see cref="IValidator"/>
48 /// instance based on the properties set on the attribute instance.
50 /// <returns></returns>
51 public override IValidator
Build()
53 IValidator validator
= new RegularExpressionValidator(pattern
);
55 ConfigureValidatorMessage(validator
);