Capitalizing alphabetic character input using jquery and css

Do you need to capitalize every single character that the user inputs in your text field? Well, here’s another quick tip on how to capitalize characters using jquery and css.

Jquery
To capitalize alphabetical characters in jquery:

$('input[type=text]').blur(function() {
    $(this).val($(this).val().toUpperCase());
});

Its more pleasant to do it on blur. Because its really very invasive if you do it on keyup event. Keyup doesn’t really transform characters on real time. And you can’t do anything with ctrl + a because of the keyup event.

 

Css
A more natural way to do this is using css:

input {
  text-transform: uppercase;
}

You’ll know what I mean once you try it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s