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 a valid decimal number by erayoral
Posted: 29 Nov 02

For example, we have a text field that must include only decimal numbers ( numbers containing "." ). If the user enters a number without a dot ( "." ), it is ok. But if
he/she enters one with a dot ( e.g. 1212.??? ), we must prevent the user from entering a second dot.

Here is the code:

If the user enters non-digit characters, they are removed.
Also a dot at the beginning is not allowed, while a dot
at the end is OK. As soon as a second dot is entered, it is
removed.



<html>

<head>

<script language="JavaScript">

  function ondalikSayiKontrol( alan ) {

    var msg=alan.value;
    var w;
    var nokta=msg.indexOf( "." );
    var ind;
  
    for ( w=0; w<msg.length; w++ )  {

      ind=msg.substring(w,w+1);
      if ( ind<"0" || ind>"9" )  {
    
           if ( nokta>0 )
             if ( w==nokta )  continue;    
       
           msg=msg.substring(0,w);
           alan.value=msg;
           break;           
      }

    }

  }

</script>

<title>Deneme</title>

</head>

<body>

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

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

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

</form>

</body>

</html>


Hope this is helpful!
Please make us aware for better solutions!
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