<input id="test" type="text" />
<script>
var elem = document.getElementById( 'test' ),
oldFirstNumber = "";
elem.onkeyup = function() {
var num = this.value.replace( /[^\d]+/g, '' ).substr( 0, 1 );
if ( num != oldFirstNumber ) {
oldFirstNumber = num;
if ( num == 7 ) {
alert( "Ввели семерку" );
} else if ( num == 3 ) {
alert( "Ввели тройку" );
}
}
}
</script>