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
- SctClaimSerializer.cs
- SerializationInfo.cs
- Decorator.cs
- WindowClosedEventArgs.cs
- TableCellAutomationPeer.cs
- CalloutQueueItem.cs
- GenerateTemporaryTargetAssembly.cs
- CompilationLock.cs
- handlecollector.cs
- OraclePermission.cs
- StatusBarPanelClickEvent.cs
- ParsedAttributeCollection.cs
- Int32.cs
- TypeLoadException.cs
- RoleGroupCollection.cs
- RawStylusInputCustomDataList.cs
- FileVersion.cs
- RuleEngine.cs
- Merger.cs
- ProfileProvider.cs
- Rule.cs
- SiteMapDataSourceView.cs
- DataGridColumn.cs
- XsdDuration.cs
- XmlSerializationReader.cs
- DesignBinding.cs
- UnSafeCharBuffer.cs
- ProcessManager.cs
- ECDiffieHellmanPublicKey.cs
- NotSupportedException.cs
- EditorBrowsableAttribute.cs
- XmlWrappingReader.cs
- RedistVersionInfo.cs
- Timeline.cs
- Bits.cs
- BitmapCacheBrush.cs
- DataSourceCache.cs
- SqlComparer.cs
- DataPagerFieldItem.cs
- SessionStateModule.cs
- InputReport.cs
- ListChangedEventArgs.cs
- EndpointInstanceProvider.cs
- CalendarDataBindingHandler.cs
- DataServiceHost.cs
- SqlClientWrapperSmiStreamChars.cs
- CallSite.cs
- PersonalizablePropertyEntry.cs
- sapiproxy.cs
- x509utils.cs
- FormViewModeEventArgs.cs
- DesignTimeValidationFeature.cs
- DuplexSecurityProtocolFactory.cs
- ScriptModule.cs
- ImportCatalogPart.cs
- RequiredFieldValidator.cs
- NullableDoubleMinMaxAggregationOperator.cs
- InvalidCommandTreeException.cs
- PackagingUtilities.cs
- DefaultEventAttribute.cs
- LocationUpdates.cs
- AlignmentYValidation.cs
- MD5CryptoServiceProvider.cs
- WhitespaceRule.cs
- CacheRequest.cs
- ContextMenu.cs
- DataPagerFieldCollection.cs
- ResolveNextArgumentWorkItem.cs
- ACE.cs
- MaterialGroup.cs
- XsdDuration.cs
- TextBoxAutoCompleteSourceConverter.cs
- RoleGroupCollection.cs
- TimeoutException.cs
- IgnorePropertiesAttribute.cs
- FacetDescription.cs
- TemplateControlBuildProvider.cs
- StreamSecurityUpgradeInitiatorBase.cs
- FakeModelPropertyImpl.cs
- MessageBodyDescription.cs
- AttachedPropertyMethodSelector.cs
- Type.cs
- WebPartCancelEventArgs.cs
- HebrewCalendar.cs
- HtmlForm.cs
- ListBoxItemAutomationPeer.cs
- SqlComparer.cs
- TypeBuilderInstantiation.cs
- EntityDataSourceSelectingEventArgs.cs
- CryptographicAttribute.cs
- Model3DCollection.cs
- OAVariantLib.cs
- ApplicationBuildProvider.cs
- TokenBasedSet.cs
- Hashtable.cs
- GB18030Encoding.cs
- InputLanguageManager.cs
- MD5.cs
- SoapEnumAttribute.cs
- DeflateStream.cs