C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » JavaScript »

How to enter only numeric values in textbox


Posted Date: 30 Oct 2009      Posted By: Nazia Suman      Member Level: Silver     Points: 1   Responses: 6



Hi

May I know how to enter only numeric values in a textbox using Javascript..
It should accept decimal values also.

If character is entered then it will show an alert..






Responses

Author: Lalji    30 Oct 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

you can visit this article

http://www.dotnetspider.com/resources/3138-How-make-Numeric-Textbox-using-JavaScript-at.aspx



Author: Nikhil Gaur    30 Oct 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

look at the following link

http://niksgaur.blogspot.com/2009/07/enter-only-digits-in-textbox.html

Join this campus group
http://www.dotnetspider.com/sites/637/-ecb-aspdotnet.aspx

Thanks & Regards
NIks
My Software and Web Development Experience



Author: Gaurav Arora    30 Oct 2009Member Level: DiamondRating: 4 out of 54 out of 54 out of 54 out of 5     Points: 6

Nazia Suman,

I prefer you to use RegularExpression.

Check this DNS link:

http://www.dotnetspider.com/forum/227927-RegEx.aspx

If you want to use it through Javascript then you can also use RegExpression, also there is another way touse KeyCode of the javascript

refer to this link which tell you for all KeyCode and it handling:
http://asquare.net/javascript/tests/KeyCode.html



Thanks & regards,
Gaurav Arora - Sr. Editor
Me in My Own Style



Author: Anil Kumar Pandey    30 Oct 2009Member Level: DiamondRating: 4 out of 54 out of 54 out of 54 out of 5     Points: 6

try this function


function IsNumeric(strString)
// check for valid numeric strings
{
var strValidChars = "0123456789.-";
var strChar;
var blnResult = true;

if (strString.length == 0) return false;

// test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
}

// -->



Thanks & Regards
Anil Kumar Pandey



Author: vineeth kumar    30 Oct 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

hi ....
just tyr this it will work for ur requirment

function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
</script>
<form>
Numbers Only: <input type='text' id='numbers'/>
<input type='button'
onclick="isNumeric(document.getElementById('numbers'), ' Only Numbers are allowed Please')"
value='Check Field' />
</form>



Author: Deepika Haridas    30 Oct 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Hello,

You can write this in keypress event

int x = e.KeyChar;
if (x >= 48 && x <= 57)
{
e.Handled = false;
}
else
{
e.Handled = true;
txtpages.Text = "";
}




Thanks & Regards,
Deepika
Editor

If U want to shine like a SUN..First U have to burn like the SUN!!
Need a Guide? Join my mentor program..



Post Reply
You must Sign In to post a response.
Next : How to find date within a given range using javascript
Previous : How to make numeric textbox
Return to Discussion Forum
Post New Message
Category: JavaScript

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use