Results 1 to 2 of 2

Thread: validation problem

  1. #1
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default validation problem

    how to restrict user not to enter any string type (by showing warning message)value in textbox which accepts only numeric value

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Here are 2 simple functions to validate the entry of a whole number or a numeric value that includes decimals.

    HTML Code:
    <html>
    <head>
    <script>
    function wholenum(fieldwval){
    wholeval=fieldwval.value;
    if (wholeval != parseInt(wholeval)){
    alert(wholeval + ' is not a whole number');
    testform.whole.name.select();
    testform.whole.name.focus();
    }
    }
    
    function numfield(fieldval){
    numval=fieldval.value;
    if (numval != parseFloat(numval)){
    alert(numval + ' is not a number');
    testform.number.name.select();
    testform.number.name.focus();
    }
    }
    
    </script>
    </head>
    <body>
    <form name="testform">
    <input type="text" name="whole" onBlur="wholenum(this)">Enter a whole number
    <br>
    <input type="text" name="number" onBlur="numfield(this)">Enter any number (incl. decimals)
    </html>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •