1

Is there a way to capitalize the first letters of a name when inputting it into the textbox?

For example, when one types john doe, the textbox should display John Doe.

I know it can be done in the c# code but just wondering if there is an easier way through attributes or regex.

vaibhav
  • 1,028
  • 12
  • 31
sd_dracula
  • 3,796
  • 28
  • 87
  • 158
  • may also interesting for http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript – Aristos Jun 06 '12 at 12:32

3 Answers3

7

Shouldn't be hard to do yourself if you want, other than that there's a ToTitleCase() that would probably serve your purposes.

http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase(v=vs.90).aspx

Ian Jacobs
  • 5,456
  • 1
  • 23
  • 38
5

You can do this in the markup with CSS - ff you add the CSS attribute text-transform to your textbox with a value of capitalize, it will make the first character of each word upper case e.g.

<asp:textbox runat="server" id="NameTextBox" style="text-transform:capitalize;" />

No code required :-)

PhilPursglove
  • 12,511
  • 5
  • 46
  • 68
3

Capitalize it using ToTitleCase() available in System.Globalization Namespace.

Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208