Old question. New answer.
With HTML5 Form Validation now (2021) supported across all major browsers, it is relatively simple to force lowercase text on an input field, client side, using the pattern attribute. (The pattern
attribute is supported by all but Opera Mini at the time of writing).
HTML:
<label>Field Name (lowercase letters only)</label>
<input type="text" pattern="[a-z]" placeholder="Field Name (lowercase letters only)">
Note: The below follows from but gets semi out of scope of the question.
Forcing lowercase on an email address field (which is what brought me to this question) seems to be more risky as using pattern
/rejex to validate email addresses is fairly complicated and there are potential issues associated with implementing pattern
in conjunction with type="email".
The above aside, for my use case, the following pattern
was sufficient:
<label>Email Address (lowercase letters only)</label>
<input type="email" pattern="[^A-Z]+" placeholder="Email Address (lowercase letters only)">
The rejex expression [^A-Z]+
allows any characters that aren't capitals. I leave the actual email address validation to the browser via type="email"
. I tested this on desktop in Chrome, Firefox, Edge and IE11 and all worked fine.