INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Validation

Ensure that the user enters only digits by erayoral
Posted: 29 Nov 02

For example, we have a text field and want users to enter
only digits.

The function is triggered with "onKeyUp" action and starts
to check the characters if they are digits or not.As soon as
it finds a non-digit character, it removes the rest of the text and updates the text field's value.


<html>

<head>

<script language="JavaScript">

  function numericKontrol( alan )  {

    var msg=alan.value;
    var chr;

    for ( i=0; i < msg.length; i++ )  {
      chr=msg.substring(i,i+1);
      if ( chr<"0" || chr>"9" )  {
    msg=msg.substring(0,i);
    alan.value=msg;
      }
    }
  }

</script>

<title>Deneme</title>

</head>

<body>

<form name="form1" method="post" action="gonder.html">

  <input name="Txt01" type="text" value=""
    size="30" onKeyUp="numericKontrol(this)"><br>

  <input type="button" value="Gonder">
  <input type="Reset" value="Temizle">

</form>

</body>

</html>



Hope this helps somebody!
Eray Oral ( marmara )

Back to Javascript FAQ Index
Back to Javascript Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close