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

Unable to create custom message for EPiServer Forms Regular Expression Validator

Vote:
 

I'm running on EPiServer 10.0.1 and EPiServer Forms 4.1.

I'm trying to use the built in Regular Expression validation for an episerver forms element (Textbox in this case) but without any luck.

If I specify an regex for an Organisation Number in EPiServer UI as follows "^(\d{1})(\d{5})\-(\d{4})$" the validation will work fine for the user but if it fail it will show the message:

"This field should be in "^(\d{1})(\d{5})\-(\d{4})$" format. I would like the message to be ""This field should be in "999999-9999" format". If I change in the UI field for the regex to "999999-9999" it will show the correct message but the built in regex will not work.

When I reflect the code from EPiServer.Forms assembly I notice that the dotNetPattern variable is used both for the message:

regularExpressionValidationModel.Message = string.Format(regularExpressionValidationModel.Message, regularExpressionValidationModel.DotNetPattern);

And as well for the regex Ismatch:

result = new bool?(Regex.IsMatch(text, dotNetPattern));

Is there a way that I can use a different custom pattern message for the Message?

I've added the custom translations to the language file as follows:





Regular expression
This field should be in following {0} format.



And that overrides the default, but I can't figure out how to render the custom message pattern in the {0}. 

 

I tried to add a custom validator instead so I can both handle the pattern and the message separately from this guide:

https://blog.i4code.nl/custom-validators-with-episerver-forms/

But it doesn't show up in the UI at all unfortunately.

Any help much appreciated.

//J

#174313
Jan 24, 2017 11:54
Vote:
 

http://world.episerver.com/documentation/developer-guides/forms/create-custom-form-element-with-validator/

#174631
Feb 01, 2017 8:56
* 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.