Search code examples
jqueryhtmlrequiredfieldvalidator

How to edit "required" attribute, and set it from jquery


is there some way to edit the messages shown when a require input field is not filled?

Can I check if a specific field content is valid (according to some rules) and eventually add the required attribute and activate it? Otherwise, is there some CSS rules to make the border red and show the messagebox?

Thanks in advance


Solution

  • I assume u r using jquery validation plugin... To change required message for all use below..

    $.validator.messages.required = 'required';
    

    to change for particular element use below...

    $("#EnquiryText").rules("remove"); 
    $("#EnquiryText").rules("add", { 
        required: true, 
        messages: { 
            required: <your message>
        } 
    });