Convert first letter to uppercase on input box

后端 未结 8 1306
梦如初夏
梦如初夏 2020-12-11 04:38

JS Bin demo

This regex transform each lower case word to upper case. I have a full name input field. I do want the user to see that each word\'s first letter he/she

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 05:32

    This will do for every textfield call function on keyup

    where id is id of your textfield and value is value you type in textfield

    function capitalizeFirstLetter(value,id)
    {
    
        if(value.length>0){
    
            var str= value.replace(value.substr(0,1),value.substr(0,1).toUpperCase());
            document.getElementById(id).value=str;
    
        }
    
    }
    

提交回复
热议问题