How to manage custom formatting and validation for numeric form fields

If you’re using WorkflowGen’s default ASP.NET RangeValidator control to validate numeric values that contain thousand separators (for example, 123,456.78 in the en-US language/culture, or 123 456,78 in the fr-FR language/culture), you’ll need to perform this workaround, which must be done for each numeric form field.

Steps 1 and 2 will format and display the default values in the form fields according to the current user’s language/culture setting. Steps 3 and 4 will prevent the default numeric RangeValidator control from validating the field value by adding a custom regex validator. Step 5 is optional, and will automatically format the input value based on the language/culture.

This example uses the format for the fr-FR language/culture.

  1. Set the field format to Numeric. This sets a fielddatatype attribute with the Numeric value at the field level.

  2. Add another custom attribute field format with the value {0:N2}, so that the formatted value will use a space as the thousand separator and a comma as the decimal separator (for example, 123 456,78).

  3. Add a regex validation at the field level to validate numeric values in the 123 456,78 format:

    • Expression: ^-?([0-9]+[(\u00A0| )]?)*[\\,]?([0-9]*)$

    • Error message: You have entered an invalid numeric value!

  4. In the .NET editor, add the following code to disable the default numeric RangeValidator for the specific fields.

    protected void Page_PreRender(object sender, EventArgs e)
    {
        base.Page_PreRender(sender, e);
        System.Web.UI.WebControls.RangeValidator rv = this.FindControl("WFGEN_RV_REQUEST_NUMERIQUE1") as System.Web.UI.WebControls.RangeValidator;
        rv.Enabled = false;
    }
    
  5. Optional: To automatically format the input value to fr-FR, add a custom onchange attribute with the following JavaScript code as the value:

    var f=this.value.replace(/\u00A0/g,'').replace(/ /g, '').replace(/,/g, '.');
    this.value=parseFloat(f).toLocaleString("fr-FR");