Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- IPEndPointCollection.cs
- SizeChangedEventArgs.cs
- DocumentPageHost.cs
- SqlFunctions.cs
- XmlNamespaceMapping.cs
- ReadOnlyPermissionSet.cs
- PrivateUnsafeNativeCompoundFileMethods.cs
- Activator.cs
- SerializationStore.cs
- Model3D.cs
- CodeMethodInvokeExpression.cs
- TemplateAction.cs
- SemaphoreSecurity.cs
- BitmapCacheBrush.cs
- DbConnectionHelper.cs
- ColumnWidthChangingEvent.cs
- ToolStripPanelRow.cs
- HtmlControlPersistable.cs
- FileSystemInfo.cs
- TextLine.cs
- cookieexception.cs
- HybridWebProxyFinder.cs
- MessageHeaderT.cs
- EntityContainerEntitySet.cs
- HttpHandlerActionCollection.cs
- FormatSettings.cs
- Figure.cs
- ImportCatalogPart.cs
- RegexStringValidator.cs
- CommandField.cs
- AuthStoreRoleProvider.cs
- KnownBoxes.cs
- EventData.cs
- CookielessHelper.cs
- DispatcherObject.cs
- PenThread.cs
- XmlTextReaderImpl.cs
- DiagnosticsConfigurationHandler.cs
- QilExpression.cs
- StyleCollection.cs
- LineGeometry.cs
- PaintValueEventArgs.cs
- PhysicalAddress.cs
- SQLInt32.cs
- HierarchicalDataBoundControl.cs
- DataControlFieldHeaderCell.cs
- TagNameToTypeMapper.cs
- ForAllOperator.cs
- CallTemplateAction.cs
- RenderTargetBitmap.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- XmlNamespaceDeclarationsAttribute.cs
- NavigationEventArgs.cs
- PrintDocument.cs
- XmlName.cs
- DataGridViewComboBoxColumn.cs
- TimelineCollection.cs
- ListBox.cs
- clipboard.cs
- ClientScriptManagerWrapper.cs
- DateTimeFormatInfoScanner.cs
- MultiView.cs
- HuffModule.cs
- IsolatedStorageSecurityState.cs
- MethodImplAttribute.cs
- ImageUrlEditor.cs
- WindowProviderWrapper.cs
- XPathNodeIterator.cs
- Renderer.cs
- ItemDragEvent.cs
- DataSourceHelper.cs
- COM2PropertyBuilderUITypeEditor.cs
- RegexParser.cs
- CrossAppDomainChannel.cs
- ProgressBarRenderer.cs
- ZipIOExtraField.cs
- DefaultHttpHandler.cs
- Byte.cs
- COM2EnumConverter.cs
- TraceContext.cs
- GuidTagList.cs
- SettingsPropertyValueCollection.cs
- BCLDebug.cs
- EncodingFallbackAwareXmlTextWriter.cs
- GridViewColumnCollection.cs
- GeometryGroup.cs
- SqlFileStream.cs
- AnnotationAuthorChangedEventArgs.cs
- MutexSecurity.cs
- Win32Native.cs
- EventLogEntry.cs
- WebPartConnectionsConfigureVerb.cs
- ServiceReference.cs
- VectorCollectionConverter.cs
- SortFieldComparer.cs
- Native.cs
- AmbientEnvironment.cs
- OSFeature.cs
- ConfigXmlAttribute.cs
- RenameRuleObjectDialog.Designer.cs