Thứ Hai, 25 tháng 2, 2013

Không cho nhập kí tự (chữ) vào ô textbox sử dụng javasrcipt


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>
function keyPhone(e)
{
var keyword=null;
    if(window.event)
    {
    keyword=window.event.keyCode;
    }else
    {
        keyword=e.which; //NON IE;
    }
   
    if(keyword<48 || keyword>57)
    {
        if(keyword==48 || keyword==127)
        {
            return ;
        }
        return false;
    }
}

</script>
</head>

<body>
Nhap so dien thoai :
<input name="phone" type="text" onkeypress="return keyPhone(event);"/>
</body>
</html>

1 nhận xét: