How could I force the text in the "username" text input
to be lower-case regardless of what user types?
<div class="register"> <label for="username">Select username:</label> </div> <div class="registerform"> <input name="username" class="registerfont" type="text" id="username" maxlength="15" style="height:35px; width:300px"> </div>
Add text-transform: lowercase; for this field.
Use keyup() method to trigger the keyup event when user releases the key from keyboard. Use toLocaleUpperCase() method to transform the input to uppercase and again set it to the input element.
In Python, lower() is a built-in method used for string handling. The lower() method returns the lowercased string from the given string. It converts all uppercase characters to lowercase. If no uppercase characters exist, it returns the original string.
As an aid to form validation we can use HTML5 input patterns to flag when an input is not valid. In the JavaScript examples, the pattern to enforce only uppercase (assuming a single word - no spaces or punctuation) is: <input ... pattern="[A-Z]*" ...>
in CSS:
form input[type="text"] { text-transform: lowercase; }
otherwise in JS:
var text="this is my text."; var lowercase=text.toLowerCase();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With