Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / UI / WebControls / RegularExpressionValidator.cs / 1 / RegularExpressionValidator.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.Web.UI.WebControls {
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Text.RegularExpressions;
using System.Drawing.Design;
using System.Web;
using System.Security.Permissions;
using System.Web.Util;
///
/// Checks if the value of the associated input control matches the pattern
/// of a regular expression.
///
[
ToolboxData("<{0}:RegularExpressionValidator runat=\"server\" ErrorMessage=\"RegularExpressionValidator\">{0}:RegularExpressionValidator>")
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class RegularExpressionValidator : BaseValidator {
///
/// Indicates the regular expression assigned to be the validation criteria.
///
[
WebCategory("Behavior"),
Themeable(false),
DefaultValue(""),
Editor("System.Web.UI.Design.WebControls.RegexTypeEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
WebSysDescription(SR.RegularExpressionValidator_ValidationExpression)
]
public string ValidationExpression {
get {
object o = ViewState["ValidationExpression"];
return((o == null) ? String.Empty : (string)o);
}
set {
try {
Regex.IsMatch(String.Empty, value);
}
catch (Exception e) {
throw new HttpException(
SR.GetString(SR.Validator_bad_regex, value), e);
}
ViewState["ValidationExpression"] = value;
}
}
///
///
/// AddAttributesToRender method
///
protected override void AddAttributesToRender(HtmlTextWriter writer) {
base.AddAttributesToRender(writer);
if (RenderUplevel) {
string id = ClientID;
HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering) ? writer : null;
AddExpandoAttribute(expandoAttributeWriter, id, "evaluationfunction", "RegularExpressionValidatorEvaluateIsValid", false);
if (ValidationExpression.Length > 0) {
AddExpandoAttribute(expandoAttributeWriter, id, "validationexpression", ValidationExpression);
}
}
}
///
///
/// EvaluateIsValid method
///
protected override bool EvaluateIsValid() {
// Always succeeds if input is empty or value was not found
string controlValue = GetControlValidationValue(ControlToValidate);
Debug.Assert(controlValue != null, "Should have already been checked");
if (controlValue == null || controlValue.Trim().Length == 0) {
return true;
}
try {
// we are looking for an exact match, not just a search hit
Match m = Regex.Match(controlValue, ValidationExpression);
return(m.Success && m.Index == 0 && m.Length == controlValue.Length);
}
catch {
Debug.Fail("Regex error should have been caught in property setter.");
return true;
}
}
}
}
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- UTF8Encoding.cs
- NonSerializedAttribute.cs
- baseshape.cs
- ProviderUtil.cs
- TransactedReceiveData.cs
- FlowDocumentView.cs
- ILGen.cs
- ServiceReference.cs
- ColumnReorderedEventArgs.cs
- BrushValueSerializer.cs
- DBAsyncResult.cs
- CurrencyWrapper.cs
- NewArrayExpression.cs
- SafeNativeMethods.cs
- ClientOperationFormatterProvider.cs
- TimeManager.cs
- GeometryValueSerializer.cs
- MediaScriptCommandRoutedEventArgs.cs
- PersonalizablePropertyEntry.cs
- TextEditorDragDrop.cs
- DirectionalLight.cs
- NewItemsContextMenuStrip.cs
- StyleSheetRefUrlEditor.cs
- InfoCardAsymmetricCrypto.cs
- RtType.cs
- JavaScriptString.cs
- WindowsScrollBar.cs
- ActivityXamlServices.cs
- ShutDownListener.cs
- DoubleMinMaxAggregationOperator.cs
- AggregationMinMaxHelpers.cs
- EdmType.cs
- GuidTagList.cs
- MdbDataFileEditor.cs
- QilXmlWriter.cs
- WindowsListView.cs
- TableLayoutColumnStyleCollection.cs
- UnmanagedMemoryStream.cs
- XmlSchemaObject.cs
- OleDbCommand.cs
- RegexGroupCollection.cs
- TypeSchema.cs
- RootBrowserWindow.cs
- Attachment.cs
- StreamUpdate.cs
- CreateRefExpr.cs
- MetadataSerializer.cs
- followingsibling.cs
- ConfigViewGenerator.cs
- CodeDomConfigurationHandler.cs
- Config.cs
- ListItemParagraph.cs
- ContainerControlDesigner.cs
- infer.cs
- DataTableClearEvent.cs
- FacetValues.cs
- Native.cs
- COM2FontConverter.cs
- MouseDevice.cs
- VSWCFServiceContractGenerator.cs
- ExtendedProperty.cs
- PrimarySelectionGlyph.cs
- Panel.cs
- RTLAwareMessageBox.cs
- Vector3dCollection.cs
- ConsoleTraceListener.cs
- WebHeaderCollection.cs
- MethodAccessException.cs
- Unit.cs
- tibetanshape.cs
- Options.cs
- __Error.cs
- EtwTrackingBehaviorElement.cs
- GeneralTransformCollection.cs
- ControlValuePropertyAttribute.cs
- UTF32Encoding.cs
- TcpServerChannel.cs
- HandlerFactoryCache.cs
- SqlError.cs
- ListBoxItemWrapperAutomationPeer.cs
- InstanceCompleteException.cs
- PackageProperties.cs
- ControlBuilder.cs
- DummyDataSource.cs
- followingquery.cs
- RegexRunnerFactory.cs
- MetricEntry.cs
- WmpBitmapEncoder.cs
- MembershipPasswordException.cs
- StringResourceManager.cs
- X509CertificateChain.cs
- WebPartCatalogAddVerb.cs
- ExtendedProperty.cs
- BasicCommandTreeVisitor.cs
- ListViewGroup.cs
- EditBehavior.cs
- XPathEmptyIterator.cs
- ApplicationCommands.cs
- DragSelectionMessageFilter.cs
- errorpatternmatcher.cs