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

Pros & Cons of Lightning Component vs. 3rd party frameworks in Salesforce UI development

Video in

Nikita drops by to share his invaluable experience of using popular 3rd party frameworks in Salesforce. http://media.blubrry.com/salesforceway/audio.xmcdn.com/group42/M05/25/57/wKgJ81rXk6XjaZIAAU_I_KtprFM998.m4a