Thursday, September 20, 2007

Restrict Alphabet Input In TextBox Using Regular Expression

<script language="javascript">
function blockChar()
var str = document.getElementById('txt').value;
str = str.replace(/[^\d]*/g,'');
document.getElementById('txt').value = str;
<body onload="javascript:document.getElementById('txt').focus();">
<input type="text" id='txt' onkeyup="blockChar();" />

Program Demo

Note:IE Supported


Pushkar Firodiya said...

I want allow "12.39" i.e i want to allow decimal point how do i do that?

windows_mss said...

hi Pushkar Firodiya ,

if u want to decimal point meanse replace the current Reg Exp with the folloing one