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
Solved

asp.net/ajax validation

Posted on 2011-09-23
7
311 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

792 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