How to convert first letter of each word to uppercase of text entering in textbox in asp.net


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CamelCase.aspx.cs" Inherits="CamelCase" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
      function myFunction(id) {
      var txt  = document.getElementById(id);
      txt.value = txt.value.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
     }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" onkeyup="myFunction(this.id)"></asp:TextBox>
    </div>
    </form>
</body>
</html>

Advertisements

5 thoughts on “How to convert first letter of each word to uppercase of text entering in textbox in asp.net

  1. Thank you for this post.It is very useful..but i want to get get first letter of word after . or, also capital.how to get this?can you plz tell me.Thanks in advance..

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