Validation rule - One field is great then another

har7801 06 Aug, 2021
Is there a code that can validate that one field is greater then another.

I have a mileage start field and a mileage end.

Want to validate the end is entered greater than the start field.

Thanks

fields are mileage_start and mileage_end
GreyHead 06 Aug, 2021
Hi har7801,

I don't see anything built in to CFv6 to do this but this FAQ suggests a way to add custom JavaScript and/or PHP validation.

Bob
teldrive 07 Aug, 2021
Answer
Following examples of Bob, this worked for my
(inside of multifield areas i have insterted one "javascript custom code" with this function
jQuery.fn.form.settings.rules.customfn = function() {
field1=document.getElementById("field1").value;
field2=document.getElementById("field2").value;
let result = (field1 < field2) ? true:false;
return result;
};
and in validation rules of field2
customfn: Error message because field2 must be greater than field1
that works fine, thanks Bob
teldrive 07 Aug, 2021
just to add in validation rules of field2
Post a Reply