Solved

asp.net/ajax validation

Posted on 2011-09-23
7
313 Views
Last Modified: 2012-05-12
  <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

Thanks
0
Comment
Question by:Webboy2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36589603
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?
0
 

Author Comment

by:Webboy2008
ID: 36589793
no...i mean when someone typing the number in the textbox, like ajax.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36589987
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;
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Webboy2008
ID: 36590289
SammySeltzer:

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.

Thanks,
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36590613
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?
0
 

Author Comment

by:Webboy2008
ID: 36590681
it is when the number is typing....
0
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 36595826
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,'');
    if(!isNaN(num)){
       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,'');
    }
  }
</script>
</head>

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

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AJAX pass along a variable 3 78
Is there a way to bind the ID to the text value of the search result? 28 79
Ajax on ASP 2 63
JSON Error in ASP Page 3 34
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This article discusses how to implement server side field validation and display customized error messages to the client.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question