• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

asp.net/ajax validation

  <cc1:OboutTextBox ID="TxtProjectBudget" Width="285"  runat="server"></cc1:OboutTextBox>
    <cc2:FilteredTextBoxExtender ID="FilteredTextBoxExtender_TxtProjectBudget" ValidChars="1234567890" TargetControlID="TxtProjectBudget" runat="server"></cc2:FilteredTextBoxExtender>

I have above codes to validate by ajax toolkit.
It works fine but now i want to have a behavior like
when 1000 is typed, it will show 1,000

  • 4
  • 3
1 Solution
are you using vb or c3

This is c#

int number = 1000000000;
string whatYouWant = number.ToString("#,##0");

This gives: 1,000,000,000

Is that what you want?
Webboy2008Author Commented:
no...i mean when someone typing the number in the textbox, like ajax.
Oh, Isee.

Are you trying to ensure that comma is added or are you trying to get the comma added automatically once a number is typed?

Try this

function addCommas( sValue )
var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');

while(sRegExp.test(sValue)) {
sValue = sValue.replace(sRegExp, '$1,$0');
return sValue;
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Webboy2008Author Commented:

Please show me completed working codes included the client function in html or aspx.
My plan is to put this function in Bin folder so i can be shared.

You still didn't answer my question.

Are you trying to do validation to ensure that comma is added or are you trying to get the comma added automatically once a number is typed?
Webboy2008Author Commented:
it is when the number is typing....
Here you go.

Sorry about the delay...

Enter a number and it will format it for you as you type.

<script type="text/javascript">
  function addCommas(input){
   var num = input.value.replace(/\$|\,/g,'');
       input.value = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'');
    else{ alert('You may enter only numbers in this field!');
          input.value = input.value.replace(/[^\$\d\,\.]*$/g,'');

<input type="text" onkeyup="addCommas(this)" onchange="addCommas(this)">

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now