Skip to Content
0

Validation on the form using constraints

Sep 14, 2017 at 05:54 PM

36

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Joseph BERTHE Sep 15, 2017 at 05:04 AM
0

Hello,

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

Regards

Share
10 |10000 characters needed characters left characters exceeded
Sharath M G Sep 15, 2017 at 03:29 AM
0

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?

Share
10 |10000 characters needed characters left characters exceeded
Devisha Bhavik Sep 15, 2017 at 01:04 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded