November Happy Hour will be moved to Thursday December 5th.

Set Default REGEX Expression to custom field

Vote:
 

Hello - I'm created custom fields for things like zip codes and phone numbers with front end masking - but I'd like to aslo pre-define a regex for these fields by default.  

I'm able to overwrite the SetDefaultValues, and set the Regex Checbox to be checked by using

typeof(RegularExpressionValidator).FullName

This is easy enough. I'm pretty sure I need to use RegularExpressionAttribute to set the default regex, but I can't seem to figure out how to set this equal to a regex value by default.

This is where I'm at thus far

        public override void SetDefaultValues(ContentType contentType)
        {
            base.SetDefaultValues(contentType);
            Label = "Zip Code";
            RegularExpressionAttribute ZipCodeValidation = new RegularExpressionAttribute("(^[0-9]{5}(-[0-9]{4})?$)");
            this.Validators = string.Concat(typeof(RegularExpressionValidator).FullName, EPiServer.Forms.Constants.RecordSeparator,  typeof(RegularExpressionAttribute).FullName, ZipCodeValidation);

        }

And of course, this isn't working.  

I'd also like to know how to set the default message as well.

Thanks

#225933
Jul 30, 2020 15:20
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.