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

Forms: Bad validation warning message for regular expressions

Sia
Sia
Vote:
 

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).

Thanks,

Sia

#174576
Jan 30, 2017 17:35
Sia
Vote:
 

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,
Sia
#174652
Feb 01, 2017 13:54
Sia
Vote:
 

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" ?>
<languages>
  <language name="English" id="en">
    <episerver>
      <forms>
        <validators>
          <episerver.forms.implementation.validation.regularexpressionvalidator>
            <displayname>Regular expression</displayname>
            <message>This field should be in the correct format.</message>
          </episerver.forms.implementation.validation.regularexpressionvalidator>
        </validators>
      </forms>
    </episerver>
  </language>
</languages>

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

#174661
Feb 01, 2017 17:31
Vote:
 

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

#179432
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.