Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Configuration / System / Configuration / RegexStringValidator.cs / 1 / RegexStringValidator.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Collections; using System.IO; using System.Reflection; using System.Security.Permissions; using System.Xml; using System.Collections.Specialized; using System.Globalization; using System.ComponentModel; using System.Security; using System.Text; using System.Text.RegularExpressions; namespace System.Configuration { public class RegexStringValidator : ConfigurationValidatorBase { private string _expression; private Regex _regex; public RegexStringValidator(string regex) { if (string.IsNullOrEmpty(regex)) { throw ExceptionUtil.ParameterNullOrEmpty("regex"); } _expression = regex; _regex = new Regex(regex, RegexOptions.Compiled); } public override bool CanValidate(Type type) { return (type == typeof(string)); } public override void Validate(object value) { ValidatorUtils.HelperParamValidation(value, typeof(string)); if (value == null) { return; } Match match = _regex.Match((string)value); if (!match.Success) { throw new ArgumentException(SR.GetString(SR.Regex_validator_error, _expression)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Collections; using System.IO; using System.Reflection; using System.Security.Permissions; using System.Xml; using System.Collections.Specialized; using System.Globalization; using System.ComponentModel; using System.Security; using System.Text; using System.Text.RegularExpressions; namespace System.Configuration { public class RegexStringValidator : ConfigurationValidatorBase { private string _expression; private Regex _regex; public RegexStringValidator(string regex) { if (string.IsNullOrEmpty(regex)) { throw ExceptionUtil.ParameterNullOrEmpty("regex"); } _expression = regex; _regex = new Regex(regex, RegexOptions.Compiled); } public override bool CanValidate(Type type) { return (type == typeof(string)); } public override void Validate(object value) { ValidatorUtils.HelperParamValidation(value, typeof(string)); if (value == null) { return; } Match match = _regex.Match((string)value); if (!match.Success) { throw new ArgumentException(SR.GetString(SR.Regex_validator_error, _expression)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TextDecorationLocationValidation.cs
- GAC.cs
- RowsCopiedEventArgs.cs
- BeginStoryboard.cs
- XmlSchemaFacet.cs
- QilXmlWriter.cs
- EpmSyndicationContentSerializer.cs
- Faults.cs
- MemberMaps.cs
- _StreamFramer.cs
- HtmlWindowCollection.cs
- EnumerableRowCollection.cs
- NotSupportedException.cs
- RepeatButtonAutomationPeer.cs
- ObjectStateEntry.cs
- IntSecurity.cs
- PointLightBase.cs
- GridViewItemAutomationPeer.cs
- SynthesizerStateChangedEventArgs.cs
- ConfigurationValidatorBase.cs
- Exception.cs
- EditingCommands.cs
- RequiredArgumentAttribute.cs
- ImportDesigner.xaml.cs
- WsatAdminException.cs
- followingquery.cs
- WebPartsPersonalizationAuthorization.cs
- Assembly.cs
- Rotation3DAnimation.cs
- WebPartMinimizeVerb.cs
- ExcCanonicalXml.cs
- SchemaElementLookUpTable.cs
- ToolStripArrowRenderEventArgs.cs
- CacheChildrenQuery.cs
- Queue.cs
- BamlBinaryReader.cs
- KeyboardEventArgs.cs
- activationcontext.cs
- Int32Rect.cs
- Run.cs
- AdornerPresentationContext.cs
- processwaithandle.cs
- TrustExchangeException.cs
- dsa.cs
- ScriptControlManager.cs
- RawStylusInputCustomData.cs
- DirectionalLight.cs
- CheckBoxRenderer.cs
- Int64KeyFrameCollection.cs
- LocalFileSettingsProvider.cs
- GroupBox.cs
- TitleStyle.cs
- NameValueCollection.cs
- IDispatchConstantAttribute.cs
- StringConverter.cs
- DispatcherObject.cs
- ContentControl.cs
- FormViewRow.cs
- DataGridViewCellMouseEventArgs.cs
- ObjectStateFormatter.cs
- Size.cs
- SafeEventLogWriteHandle.cs
- ExpressionBuilder.cs
- DateTimeOffsetConverter.cs
- WSHttpTransportSecurityElement.cs
- documentation.cs
- PartialTrustVisibleAssembliesSection.cs
- DescendentsWalkerBase.cs
- CapabilitiesUse.cs
- OLEDB_Util.cs
- TextAutomationPeer.cs
- JournalEntry.cs
- DistinctQueryOperator.cs
- ConfigurationValues.cs
- OracleConnectionStringBuilder.cs
- RuleSetReference.cs
- XmlDataCollection.cs
- SqlCacheDependencySection.cs
- UserPreferenceChangingEventArgs.cs
- OperatingSystem.cs
- BuildProvidersCompiler.cs
- ListMarkerSourceInfo.cs
- Bitmap.cs
- ConnectionsZone.cs
- WebBrowsableAttribute.cs
- FormViewDeletedEventArgs.cs
- Label.cs
- ViewBase.cs
- HttpConfigurationContext.cs
- NativeMethods.cs
- FixedSOMContainer.cs
- BuildProviderInstallComponent.cs
- SystemIPv4InterfaceProperties.cs
- ManagementObjectCollection.cs
- CodeFieldReferenceExpression.cs
- XmlQuerySequence.cs
- InvalidCastException.cs
- AudioLevelUpdatedEventArgs.cs
- SqlProfileProvider.cs
- TokenBasedSetEnumerator.cs