ASP.NET Data Formatting

M

Morys Kenworthy

I am trying to format some textboxes that I have in my ASP.NET web page.

Can someone tell me if this is possible to do in ASP.NET?
VALUE IN TEXTBOX1 = 500000
VALUE IN TEXTBOX2 = 081604
VALUE IN TEXTBOX3 = 548554486

I would like the user to see the following when they are typing the values
or after they leave the textbox:
VALUE IN TEXTBOX1 = $500,000.00
VALUE IN TEXTBOX2 = 08/16/2004
VALUE IN TEXTBOX3 = 548-55-4486

Thank you for your time.
 
K

Karl

To get this in "real time" you'll need to use javascript...just do a good
search for javascript formatters or something.

I just happened to write a function for money:
function formatAsMoney(mnt) {
var amount = String(mnt);
var formatted = '';
for (var i = amount.length-1, t = 1; i >= 0; --i, ++t){
if ((t % 3) == 0){
formatted = ',' + amount.substr(i,1) + formatted;
}else{
formatted = amount.substr(i,1) + formatted;
}
}
if (formatted.substr(0,1) == ','){
formatted = formatted.substr(1,formatted.length-1);
}
return formatted;
}

<input type="text" onKeyUp="this.value = formatAsMoney(this.value);">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top