How to make everything lowercase automatically in Javascript as they type it in

后端 未结 6 1243
既然无缘
既然无缘 2021-02-13 02:35

How do I make all of the characters of a text box lowercase as the user types them into a text field in Javascript?



        
6条回答
  •  不知归路
    2021-02-13 03:30

    Does it only have to display in lowercase, or does it have to be lowercase? If you want to display lowercase, you can use CSS text-transform: lowercase.

    You need to enforce this constraint server-side anyway, because the user can disable any JS code you put in to enforce that it remains lowercase.

    My suggestion: use the CSS text-transform to make it always display in lowercase, and then do a toLower or your language's variant of it on the server-side before you use it.

提交回复
热议问题