Skip to Content

Validation on the form using constraints

Hi,

I have form with some fields and validations attached to it.

I have added the constraints to validate the data. Everything works fine and it gives the error if wrong data or in wrong format.

Unfortunately, it shows error on the optional field as well because I have added the constraint to it to validate data in the correct format. I have phone field and I need data in the format xxx-xxx-xxxx.

For this, i have added below constraint.

<Input id="iCommNum" maxLength="12" value="{path: 'AddAddress>/Number1', formatter: '.formatter.formatTelephone', type:'sap.ui.model.type.String' , constraints : { search : '^\\d{3}-\\d{3}-\\d{4}' }}" width="10em" type="Tel" placeholder="XXX-XXX-XXXX"/>

With this, even value is blank, it throws an error. I want to show error only if user enters something and not in the correct format. If no values provided, no error should be shown.

Let me know how that can be achieved.

-Bhavik

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Sep 15, 2017 at 05:04 AM

    Hello,

    Have you try the UI Control sap.m.MaskInput ?

    Regards

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 15, 2017 at 03:29 AM

    Due to constraint, to check if the data entered by the user matches your regex. On empty, there will be an exception or error event thrown.

    Do you observe it when user does not click on the field, too?

    Is there any submit event which if triggerred, which results in the error?

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 15, 2017 at 01:04 PM

    Hi Sharath,

    While your answer is not on the specific constraint issue mentioned here, but that is more helpful as it provides the control ready which I was trying to do.

    Thank you.

    Bhavik

    Add comment
    10|10000 characters needed characters exceeded