how to display alert box when enter a character instead of number

Posted by Bhuwan87rawat under ASP.NET on 8/20/2012 | Points: 10 | Views : 957 | Status : [Member] | Replies : 1
in my application
i have atext box if i enter a character i want to dispaly alert box.it allow only number.
using javascript.how it is possible. i struck here.

thanks in advance

Regards
Bhuwan




Responses

Posted by: Vasanthmvp on: 8/20/2012 [Member] Starter | Points: 25

Up
0
Down
Hi, you can simply do this by checking the text box value with the regular expression. and adding onblur function to the textbox control.
<html>
<head>
<script type="text/javascript">
function check()
{
var x = document.getElementById("tb").value;
if(x.match(/^[0-9]$/))
{
return true;
}
else
{
alert("Only Numbers should be entered.");
}
}
</script>
</head>

<body>
<input type="text" id="tb" onblur="check()" />
</body>
</html>


Regards,

Awesome Coding !! :)

Bhuwan87rawat, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response