Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / System / Configuration / RegexStringValidator.cs / 1305376 / 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
- FocusChangedEventArgs.cs
- BitVector32.cs
- SqlMethodCallConverter.cs
- HostUtils.cs
- XamlContextStack.cs
- CodeLabeledStatement.cs
- TextElementCollection.cs
- GroupStyle.cs
- FileDialogCustomPlace.cs
- SpecialFolderEnumConverter.cs
- OdbcUtils.cs
- PropertyTabAttribute.cs
- HtmlWindowCollection.cs
- EventsTab.cs
- InvalidComObjectException.cs
- MruCache.cs
- UserValidatedEventArgs.cs
- CodeLinePragma.cs
- SqlBuilder.cs
- DBNull.cs
- UserNameSecurityToken.cs
- ResumeStoryboard.cs
- CalculatedColumn.cs
- DefaultPropertyAttribute.cs
- StringExpressionSet.cs
- ValueTable.cs
- StoryFragments.cs
- SqlRowUpdatingEvent.cs
- basevalidator.cs
- RunClient.cs
- DrawListViewItemEventArgs.cs
- RegexWriter.cs
- LoadedEvent.cs
- CodeBlockBuilder.cs
- WCFModelStrings.Designer.cs
- CachedBitmap.cs
- TemplateBindingExtension.cs
- StaticSiteMapProvider.cs
- iisPickupDirectory.cs
- RuntimeConfigurationRecord.cs
- HostingEnvironmentException.cs
- DataGridViewTopRowAccessibleObject.cs
- XmlSchemaRedefine.cs
- MessageSmuggler.cs
- OracleFactory.cs
- TypeEnumerableViewSchema.cs
- BrowserCapabilitiesFactory.cs
- LayoutDump.cs
- PersistenceIOParticipant.cs
- ObjectResult.cs
- StylusPointDescription.cs
- odbcmetadatafactory.cs
- MetadataHelper.cs
- WizardSideBarListControlItemEventArgs.cs
- RegexBoyerMoore.cs
- SqlWebEventProvider.cs
- MessageQueue.cs
- DesignerSerializerAttribute.cs
- CookielessHelper.cs
- StrokeIntersection.cs
- Point3DCollectionValueSerializer.cs
- SwitchAttribute.cs
- CharacterBuffer.cs
- RectangleHotSpot.cs
- BamlVersionHeader.cs
- WebPartVerbsEventArgs.cs
- PixelFormat.cs
- COMException.cs
- DocumentScope.cs
- SpnEndpointIdentity.cs
- PrePostDescendentsWalker.cs
- FormatSettings.cs
- ResourceExpressionBuilder.cs
- SectionInput.cs
- SystemIcons.cs
- CompiledAction.cs
- DataControlFieldCell.cs
- XmlAttributes.cs
- EventToken.cs
- NamespaceEmitter.cs
- SecurityHelper.cs
- CodeMethodReturnStatement.cs
- ImageCodecInfoPrivate.cs
- KeyGestureConverter.cs
- DispatcherHooks.cs
- Expressions.cs
- PageContent.cs
- DesignerCategoryAttribute.cs
- HostingEnvironment.cs
- XamlSerializationHelper.cs
- SchemaComplexType.cs
- WebPermission.cs
- MDIWindowDialog.cs
- DataGridState.cs
- ProcessStartInfo.cs
- Error.cs
- SqlPersonalizationProvider.cs
- TemplateControlCodeDomTreeGenerator.cs
- NumberFormatInfo.cs
- PersonalizationProvider.cs