I am working on a form and want user to only enter capital letters in fields.I have already given regular expression validator for this .But to make life easy for user i want to enable caps lock on from back end and also want to have it on till i desire.I searched but couldn't get nowhere.I could only manage to know the state of caps lock alone.Thanks in advance friends.
Asked
Active
Viewed 555 times
-4
-
1I'm not sure this is possible from the browser. In fact if it were I'd be a little scared. – lc. Sep 05 '12 at 10:44
-
11Why not just convert each character they enter to uppercase? – Scroog1 Sep 05 '12 at 10:44
-
Controlling the users keyboard is not allowed, and not what you should be focusing on. If you have a field that should be caps only, why not just go case insensitive? – Joakim Johansson Sep 05 '12 at 10:45
-
1I think this may be an **answer** to your question [http://stackoverflow.com/questions/202368/how-can-i-force-input-to-uppercase-in-an-asp-net-textbox] – Pilgerstorfer Franz Sep 05 '12 at 10:45
-
2In addition to the excellent points already made here - what if the user holds `shift` whilst typing with this "forced caps lock on" mode? - you'd still get lower case input. – Damien_The_Unbeliever Sep 05 '12 at 10:48
2 Answers
2
You cannot enable Caps Lock from a webpage.
What you will need to do is use a Java Script function to upper case the letters as the user types them in.
You can find details here.
I lifted the example into my answer:
<script>
function uppercase() {
key = window.event.keyCode;
if ((key > 0x60) && (key < 0x7B))
window.event.keyCode = key-0x20;
}
</script>
<input type="text" onKeypress="uppercase();" />

DaveShaw
- 52,123
- 16
- 112
- 141
1
To make life easy for user you should convert all the characters entered by used to UpperCase. If you force the user to keep CAPS lock on then for other work of user it will be always on; and that's dangerous.
To convert letters to upper case, you can make text box style:
style="text-transform:uppercase;
Or
get help from this question... How can I force input to uppercase in an ASP.NET textbox?