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
- VBCodeProvider.cs
- RemoveStoryboard.cs
- TableParagraph.cs
- ScrollProperties.cs
- Pens.cs
- SID.cs
- CustomSignedXml.cs
- COAUTHIDENTITY.cs
- EmptyEnumerable.cs
- PkcsUtils.cs
- oledbmetadatacolumnnames.cs
- ObjectDataSourceSelectingEventArgs.cs
- OdbcException.cs
- TrayIconDesigner.cs
- ConstraintConverter.cs
- PropertyStore.cs
- TargetException.cs
- ListDictionary.cs
- PEFileReader.cs
- COSERVERINFO.cs
- FixUpCollection.cs
- DataGridRow.cs
- PartialList.cs
- FontDriver.cs
- IUnknownConstantAttribute.cs
- UInt16.cs
- ProxyHwnd.cs
- Run.cs
- CodeSubDirectoriesCollection.cs
- StreamGeometry.cs
- ValidationErrorInfo.cs
- KnownColorTable.cs
- Latin1Encoding.cs
- SqlDataSource.cs
- ConvertEvent.cs
- DriveNotFoundException.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- CellParagraph.cs
- TypeInfo.cs
- GridEntry.cs
- GeneratedCodeAttribute.cs
- JournalEntryListConverter.cs
- Stroke2.cs
- WsatRegistrationHeader.cs
- CompilerLocalReference.cs
- FigureParagraph.cs
- AssemblyCache.cs
- BitmapEffectInput.cs
- PassportAuthenticationModule.cs
- CodeVariableReferenceExpression.cs
- PathSegmentCollection.cs
- CollectionViewProxy.cs
- ISFTagAndGuidCache.cs
- CopyAttributesAction.cs
- BitmapEffectGeneralTransform.cs
- PeerNameRegistration.cs
- WebPartHeaderCloseVerb.cs
- NetworkInformationPermission.cs
- WmfPlaceableFileHeader.cs
- UriTemplateVariableQueryValue.cs
- MarkupCompiler.cs
- ExpressionBuilder.cs
- LicFileLicenseProvider.cs
- ScrollChrome.cs
- TrackingProfileManager.cs
- ClickablePoint.cs
- RIPEMD160Managed.cs
- ExpressionPrinter.cs
- CodeAttributeDeclarationCollection.cs
- MethodImplAttribute.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- Token.cs
- EdmValidator.cs
- FontStyles.cs
- ADMembershipProvider.cs
- RoleManagerEventArgs.cs
- ContentPlaceHolder.cs
- FontClient.cs
- StoreContentChangedEventArgs.cs
- Funcletizer.cs
- FlowLayoutPanelDesigner.cs
- EntityDataReader.cs
- Char.cs
- EntryIndex.cs
- Style.cs
- XmlEncodedRawTextWriter.cs
- MonthChangedEventArgs.cs
- LOSFormatter.cs
- KeyConverter.cs
- CoTaskMemUnicodeSafeHandle.cs
- TableAutomationPeer.cs
- Pkcs9Attribute.cs
- OpenFileDialog.cs
- TypeLoadException.cs
- XmlSecureResolver.cs
- ObjectDataSourceDisposingEventArgs.cs
- XmlNamespaceManager.cs
- SpecularMaterial.cs
- PageAdapter.cs
- GeneralTransform.cs