Solved

asp.net/ajax validation

Posted on 2011-09-23
7
306 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
  • 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Issue with Loop 4 42
Update field in order 21 108
jQuery aJax Disable Async 24 43
Bootstrap Datable Spinner 3 31
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now