jQuery Validation - Two fields, only required to fill in one

前端 未结 7 1840
醉梦人生
醉梦人生 2020-11-30 01:20

I\'m using the jQuery Validation Plugin on my form. On my form I have a \'Telephone\' field and a \'Mobile No.\' field.

How would I go about making it so the user ha

相关标签:
7条回答
  • 2020-11-30 01:53

    Came here looking for the same answers. Found the above post very helpful. Thanks.

    I have extended this solution to check if the other field is in fact valid, rather than just "not empty". This ensures that the user inputs a valid Phone Number before removing the "required" class from the Mobile field and vice versa.

    Mobile: {
        required: function(element) {
        return (!$("#Phone").hasClass('valid'));
        }
    },
    Phone: {
        required: function(element) {
            return (!$("#Mobile").hasClass('valid'));
        }
    }
    
    0 讨论(0)
提交回复
热议问题