3 Replies - 273 Views - Last Post: 15 June 2010 - 07:49 AM

#1 William_Wilson   User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

validate number only input

Posted 04 April 2007 - 03:01 PM

Description: copy and paste, change colour as you like. *Use an onkeyup=data_change(this) attribute in html for full functionallityalso notifies the user of incorrect input, without a server connection, or annoying alert box.
function data_change(field)
     {
          var check = true;
          var value = field.value; //get characters
          //check that all characters are digits, ., -, or ""
          for(var i=0;i < field.value.length; ++i)
          {
               var new_key = value.charAt(i); //cycle through characters
               if(((new_key < "0") || (new_key > "9")) && 
                    !(new_key == ""))
               {
                    check = false;
                    break;
               }
          }
          //apply appropriate colour based on value
          if(!check)
          {
               field.style.backgroundColor = "red";
          }
          else
          {
               field.style.backgroundColor = "white";
          }
     }


Is This A Good Question/Topic? 0
  • +

Replies To: validate number only input

#2 waqas23   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 05-May 09

Re: validate number only input

Posted 21 May 2009 - 11:42 PM

Perfect JS for number validation.......
Was This Post Helpful? 0
  • +
  • -

#3 web4live   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-May 09

Re: validate number only input

Posted 17 June 2009 - 07:30 PM

excellent js for numbers validation
Was This Post Helpful? 0
  • +
  • -

#4 singularity   User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 184
  • Joined: 17-October 08

Re: validate number only input

Posted 15 June 2010 - 07:49 AM

If I have to validate a character entry rather number, do I have to put ACSII values!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1