Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / Components / Validator / Castle.Components.Validator / Attributes / ValidateRegExpAttribute.cs
blob97ec85876506b1d4b8092395a10d51741545a92f
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 /// Validate that the property match the given regular expression
21 /// </summary>
22 [Serializable, CLSCompliant(false)]
23 public class ValidateRegExpAttribute : AbstractValidationAttribute
25 private readonly string pattern;
27 /// <summary>
28 /// Initializes a new instance of the <see cref="ValidateRegExpAttribute"/> class.
29 /// </summary>
30 /// <param name="pattern">The pattern.</param>
31 public ValidateRegExpAttribute(String pattern)
33 this.pattern = pattern;
36 /// <summary>
37 /// Initializes a new instance of the <see cref="ValidateRegExpAttribute"/> class.
38 /// </summary>
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;
46 /// <summary>
47 /// Constructs and configures an <see cref="IValidator"/>
48 /// instance based on the properties set on the attribute instance.
49 /// </summary>
50 /// <returns></returns>
51 public override IValidator Build()
53 IValidator validator = new RegularExpressionValidator(pattern);
55 ConfigureValidatorMessage(validator);
57 return validator;