Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > format textbox value as number

Reply
Thread Tools

format textbox value as number

 
 
nic
Guest
Posts: n/a
 
      12-16-2003
Hi,
I have a textbox value that I need to force (and format)
to be a numeric value. For example, I want to allow a
user to type 1000 or 1,000 or 1,000,000 but not something
that is not numberic. Essentially I want to ignore the
commas. If I use the compareValidator it does not allow
commas. Is there an easy way to do this? Also I need to
format a string such as 1000 as 1,000 (without any decimal
places) When I format 1000 as a numeric it returns
1,000.00.

Thanks
 
Reply With Quote
 
 
 
 
Rick Strahl [MVP]
Guest
Posts: n/a
 
      12-16-2003
Hi Nic,

You can use Format strings to do the output generation. ToString("C")
generates numbers with the thousands separators, but unfortunately also with
the $. You can also build custom format strings, but offhand I can't
remember the format - look in the MSDN docs.

On the way in you can use decimal.Parse() with options that strip that stuff
out. I use the following in my DataBinding Controls which do the conversion
automatically.

Decimal.Parse( (string) loValue,NumberStyles.Any);

This doesn't address the client side Validators. For that you probably will
neeed to use the RegEx validation control.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/blog/
----------------------------------
Making waves on the Web


"nic" <(E-Mail Removed)> wrote in message
news:151d701c3c40b$1562b2a0$(E-Mail Removed)...
> Hi,
> I have a textbox value that I need to force (and format)
> to be a numeric value. For example, I want to allow a
> user to type 1000 or 1,000 or 1,000,000 but not something
> that is not numberic. Essentially I want to ignore the
> commas. If I use the compareValidator it does not allow
> commas. Is there an easy way to do this? Also I need to
> format a string such as 1000 as 1,000 (without any decimal
> places) When I format 1000 as a numeric it returns
> 1,000.00.
>
> Thanks



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass value from activex textbox to webform textbox AGSHAR ASP .Net 1 05-31-2008 12:00 PM
converting exponential format number to decimal format number Fei Liu Perl Misc 21 12-16-2006 01:49 AM
how to transfer textbox value from .net page to html page textbox? Steve Javascript 4 02-07-2006 06:30 PM
ASP.NET textbox loses text value in composite control but Textbox subclass doesn't!? ErwinP ASP .Net Web Controls 1 08-19-2005 01:50 PM
Format textbox to time format ruca ASP .Net Web Controls 1 05-09-2005 05:09 PM



Advertisments