Validation Form field not the same as another field on form

Hi,
I have a form field for a mobile number and an emergency mobile contact and I want to put a validation so that the user doesn't enter the same mobile number for both fields.
I've tried the following but it's not working

<input type="text" class="form-control" id="inp_usr_emerg_mobile" name="usr_emerg_mobile" aria-describedby="inp_usr_emerg_mobile_help" placeholder="Enter Emergency Contact Mobile" required="" data-rule-pattern="^0[4]\d{8}$" dmx-on:keypress="inp_usr_emerg_mobile.setValue(value.replace(' ', ''))" dmx-bind:value="!=inp_usr_mobile.value">

<input class="form-control" id="inp_usr_mobile" name="usr_mobile" aria-describedby="inp_usr_mobile_help" placeholder="Enter your Mobile" required="" data-rule-pattern="^0[4]\d{8}$" dmx-on:keypress="inp_usr_mobile.setValue(value.replace(' ', ''))">

the mistake is here:

You use the dmx-bind:value.. This is used to bind a value to an input.
You should use the data-rule-notequalto="inp_usr_mobile.value" to check the value

Thanks for the suggestion. Unfortunately thats didn't work!

<input type="text" class="form-control" id="inp_usr_emerg_mobile" name="usr_emerg_mobile" aria-describedby="inp_usr_emerg_mobile_help" placeholder="Enter Emergency Contact Mobile" required="" data-rule-pattern="^0[4]\d{8}$" data-rule-notequalto="inp_usr_mobile.value">

First of all, remove: dmx-bind:value="!=inp_usr_mobile.value" this make no sense and is invalid expression.

You need to enter just the id of the field for the validation rule. So in the Not Equal To validation applied for the second input it must be just inp_usr_emerg_mobile

Screenshot 2024-06-13 at 10.09.56

1 Like

Sorry my mistake

This is the correct:

data-rule-notequalto="usr_mobile"

1 Like

Thanks Teodor. That worked. I entered the field name in the value attribute

<input type="text" class="form-control" id="inp_usr_emerg_mobile" name="usr_emerg_mobile" aria-describedby="inp_usr_emerg_mobile_help" placeholder="Enter Emergency Contact Mobile" required="" data-rule-pattern="^0[4]\d{8}$" data-rule-notequalto="usr_mobile">

Thank you.

1 Like

Teodor is there a way to change the text for the error message. at the moment it says:

'Please enter a different value, values must not be the same.'

Screenshot 2024-06-13 at 10.21.32