forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareValidator.cs
More file actions
33 lines (28 loc) · 1.17 KB
/
Copy pathCompareValidator.cs
File metadata and controls
33 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
using System.Web.Mvc;
namespace System.Web.WebPages
{
internal class CompareValidator : RequestFieldValidatorBase
{
private readonly string _otherField;
private readonly ModelClientValidationEqualToRule _clientValidationRule;
public CompareValidator(string otherField, string errorMessage)
: base(errorMessage)
{
Debug.Assert(!String.IsNullOrEmpty(otherField));
_otherField = otherField;
_clientValidationRule = new ModelClientValidationEqualToRule(errorMessage, otherField);
}
public override ModelClientValidationRule ClientValidationRule
{
get { return _clientValidationRule; }
}
protected override bool IsValid(HttpContextBase httpContext, string value)
{
string otherValue = GetRequestValue(httpContext.Request, _otherField);
return String.Equals(value, otherValue, StringComparison.CurrentCulture);
}
}
}