Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textbox format

Status
Not open for further replies.

stevenr

Technical User
Feb 21, 2001
89
0
0
GB
I want the text in my asp:textbox to be in the format of:

123,455

How can i get the commer to go in automatically so that the user just puts in 123455?
 
what are you doing with that number? you could either do javascript onchange and check the length of the field and insert a comma or you could just handle it programatically if you submit that number somewhere else...

dlc
 
its being saved into a database, then being retrieved at a later date and it would be easier to read with the , in it.
 
can you just save it to the db in that format??

for instance

Code:
dim str as String
str = textBox1.Text
str = str.Insert(3, ",")
Response.Write(str)

will output 123,455
 
only problem is that it goes the wrong way, 1234 makes 123,4
, it should be 1,234
 
oh, i see...i didn't know it was for numbering purposes...why would you want to store it that way in the database? I believe there is a SQL function to return values to look like money...let me check...

dlc
 
Code:
print CONVERT(VARCHAR,CAST (123455 AS MONEY),1)

will print out 123,455.00


Code:
print CONVERT(VARCHAR,CAST (4500 AS MONEY),1)

will print out 4,500.00

DLC
 
VB has a function:

FormatNumber(<number>[,numOfDigitsAfterDecimal])

so:

FormatNumber(myNumber)

Would return:

123,456

and FormatNumber(myNumber, 2)

would return:

123,456.00

-p

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
This is a pretty nice javascript that would do what you want.
You hust have to modify it for your purpose

<td><input name="Field1" value="" type="text" onKeyUp="javascript:return mask(this.value,this,'3,7,11,15',',');" onBlur="javascript:return mask(this.value,this,'3,7,11,15',',');" style="font-family:verdana;font-size:10pt;width:110px;" maxlength="19"></td>

I'd would also add a
mask="999,999,999,999" and a
ValidationExpression="^\d{3},\d{3},\d{3},\d{3}$"
I think it is a nice piece of javascript worth checking out. It made me smile.
Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top