cancel
Showing results for 
Search instead for 
Did you mean: 

Validation on the form using constraints

former_member188396
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Joseph_BERTHE
Active Contributor
0 Kudos

Hello,

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

Regards

Answers (2)

Answers (2)

former_member188396
Participant
0 Kudos

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

Sharathmg
Active Contributor
0 Kudos

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?