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,038
  • 12
  • 31
sd_dracula
  • 3,672
  • 25
  • 85
  • 151
  • 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,408
  • 1
  • 22
  • 37
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,381
  • 5
  • 44
  • 68
3

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

Nikhil Agrawal
  • 44,717
  • 22
  • 115
  • 201