Forms: Bad validation warning message for regular expressions


I'm using Form Container on Episerver 9. I've added a custom regex validation for a phone number field.

The validation, itself, works fine, but when the input is not a valid phonenumber, the error message is "Validation failed on "Phone Number" field: This field should be in "^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$" format."

How can I show a simple "phone number is not valid" instead of that (without a hacky piece of js code).



Jan 30, 2017 17:35

Thanks Anish,

But that is a totally different path, which takes a lot of time. EpiServer Forms is already providing regex validation and I don't want to customize that, I just want to show the correct message for it. As you may know, ASP.NET data annotation syntax is like this:

[RegularExpression("^([a-zA-Z0-9 .&'-]+)$", ErrorMessage = "Invalid First Name")]
public string FirstName { get; set; }

This is a very common scenario for validation.

Thanks again,
Feb 01, 2017 13:54

One of my friends at work found the solution.

Create a Forms.xml inside \Resources\LanguageFiles and add this as the content:

<?xml version="1.0" encoding="utf-8" ?>
  <language name="English" id="en">
            <displayname>Regular expression</displayname>
            <message>This field should be in the correct format.</message>

That's not a very ideal solution, because it's a general message for all regex, but still works!

Feb 01, 2017 17:31

Thanks for the above workaround, this has been an issue for us too. 

Jun 12, 2017 14:22
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.