Solved

asp.net/ajax validation

Posted on 2011-09-23
7
316 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 29

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 29

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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 29

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 29

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

There is basically two types of AJAX request in mootools. Request  and Request.HTML Request: Request is the basic XHR request class in MooTools. While not extremely useful on its own, it provides the basic functionality for both Request.HTM…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

729 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