Activity Forums Salesforce® Discussions Is there any method to limit the maximum number of characters that can be typed into input field in Salesforce?

  • Abhinav

    Member
    July 29, 2016 at 1:13 pm

    Hi Pranav,

    Yes, you can call the below function :-

    ({
    limitCharacterTo : function(element, charLimit, evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if(element.value.length >= charLimit && charCode != 8) {
    return false;
    }
    }
    })

  • Ajay Prakash

    Member
    February 28, 2018 at 4:39 am

    Hi Pranav,

    You should use maxlength attribute of the input field instead of calling a method for the validation. If you want to write some custom logic or you want to show a message to the user then you can call a method and follow the approach provided by Abhinav.

    Thanks.

     

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos