Added RedirectUsingNamedRoute
[castle.git] / Components / Validator / Castle.Components.Validator / Validators / EmailValidator.cs
blobd256e8d1635220b1bc34ed1ed286b7e0c1968555
1 // Copyright 2004-2008 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;
18 using System.Collections;
20 /// <summary>
21 /// Validate that this is a valid (formatted) email using regex
22 /// </summary>
23 [Serializable]
24 public class EmailValidator : RegularExpressionValidator
26 /// <summary>
27 /// From http://www.codeproject.com/aspnet/Valid_Email_Addresses.asp
28 /// </summary>
29 private static readonly String emailRule = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
30 @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
31 @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
33 /// <summary>
34 /// Initializes a new instance of the <see cref="EmailValidator"/> class.
35 /// </summary>
36 public EmailValidator() : base(emailRule)
40 /// <summary>
41 /// Gets a value indicating whether [supports browser validation].
42 /// </summary>
43 /// <value>
44 /// <c>true</c> if [supports browser validation]; otherwise, <c>false</c>.
45 /// </value>
46 public override bool SupportsBrowserValidation
48 get { return true; }
51 /// <summary>
52 /// Applies the browser validation.
53 /// </summary>
54 /// <param name="config">The config.</param>
55 /// <param name="inputType">Type of the input.</param>
56 /// <param name="generator">The generator.</param>
57 /// <param name="attributes">The attributes.</param>
58 /// <param name="target">The target.</param>
59 public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
60 IBrowserValidationGenerator generator, IDictionary attributes,
61 string target)
63 generator.SetEmail(target, BuildErrorMessage());
66 /// <summary>
67 /// Returns the key used to internationalize error messages
68 /// </summary>
69 /// <value></value>
70 protected override string MessageKey
72 get { return MessageConstants.InvalidEmailMessage; }