Validate form and change value

Validate form and change value

I want to change field values when a form is validated.

I have a CONTACTS form with a mobile and phone field. If either are empty, I want to populate a message with instructions. As I have multiple rules, I do not want to use alerts but instead populate the contact_msg field.

I have the following code on validate

if ((input.CONTACT_MOBILE  ==  "")  &&  (input.CONTACT_PHONE_OTHER  ==  ""))
{
    input.CONTACT_MSG = "Please enter either a mobile or other phone number";
    cancel submit;
}

When I run the code with both mobile and phone fields empty, the form does not get submitted but the contact_message is not displayed correctly.
Can you please allow the field value to be changed via validation?