Convert first letter to uppercase on input box

后端 未结 8 1326
梦如初夏
梦如初夏 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:20

       $('.form-capitalize').keyup(function(event) {
            var $this = $(this),
            val = $this.val(),
            regex = /\b[a-z]/g;
            val = val.toLowerCase().replace(regex, function(letter) {
                return letter.toUpperCase();
            });
            this.value = val;
            // I want this value to be in the input field.
          console.log(val);
        });
    

提交回复
热议问题