Click here to Skip to main content
14,878,738 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi experts.

i have got a text box it should allow only numbers and comma(,)

Presently am using this java script to validate the textbox

C#
function isInteger(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
             return false;
         return true;
     }


but if i copy some text and paste in the textbox, this type of validation will not work

can any one please help me to solve this issue?

thanks in advance
Posted
Updated 10-Mar-21 23:03pm

Best option would be to use regular expression. Check this links.

https://www.google.co.in/#psj=1&q=regular+expression+in+javascript[^]

http://regexlib.com/[^]
   
you can use ajax control toolkits filter text box extender
   
Comments
Keerthi Kumar(Andar) 10-Oct-13 1:05am
   
can you give me a example?
Keerthi Kumar(Andar) 10-Oct-13 1:21am
   
Hi vaibhav mahajan,
Thanks a lot for your answer. Its working fine.
vaibhav mahajan 10-Oct-13 3:17am
   
Its Ok Keerthi.
pls mark it as answer and rate it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900