How to extract validation rules from EntLib validation block?

Topics: Validation Application Block
Jul 8, 2011 at 4:27 PM

I want extract validation rules , then transform them to client-side javascript .

I tried to search about how to use validation block in client-side javascript , but nothing found. So I want write it by myself , but I don't know how to extract validation rules.

Anyone know how to do it ? Or, is there anyway use validation block in client-side javascript? Not validation by ajax. Thanks.

Jul 9, 2011 at 6:47 PM

 

I found this project ElValWeb

Here is my test code :

        public static void ExtractRules(Type targetType , string ruleSet) {
        var settings = (ValidationSettings)ConfigurationManager.GetSection ( ValidationSettings.SectionName );
        if ( settings != null ) {
            var type = settings.Types.Where ( t => t.Name == targetType.FullName ).FirstOrDefault ( );
            if ( type != null ) {
                var data = type.Rulesets.Where ( t => t.Name == ruleSet ).FirstOrDefault();
                if ( data != null ) {
                    List<ValidatorData> validatorDatas = new List<ValidatorData> ( );
                    data.Properties.ForEach ( (p) => {
                       validatorDatas.AddRange( p.Validators.Cast<ValidatorData> ( ));
                    } );

                    data.Fields.ForEach ( (f) => {
                        validatorDatas.AddRange ( f.Validators.Cast<ValidatorData> ( ) );
                    } );
                }
            }
        }
    }

Jul 11, 2011 at 2:10 AM

Hi,

Unfortunately, validation through javascript is not supported in Enterprise Library. You may log it here as a functionality.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com