Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numeric Form Validation

Status
Not open for further replies.

stan8450

Programmer
May 3, 2002
16
CA
I have a number of validations in sequence for a form named 'orderform'. I would like the user to only be able to enter in a numeric value in a text box named 'house_size'.


any help appreciated
 
function validatehousesize()
{
if (isNaN(document.orderform.house_size))
{
alert('Numbers only');
return false;
}
return true;
}
 
To automatically strip characters you don't want use:
Code:
<input type=&quot;text&quot; onblur=&quot;this.value=numsOnly(this.value)&quot;>

function numsOnly(str){
  var output='',chars='0123456789.'
  for(i=0;i<str.length;i++{
    if(chars.indexOf(str.charAt(i))>-1){
      output+=str.charAt(i)
    }
  }
  return output;
}
 
don't you just love regular expressions? :)

function stripNonNums(str) {
return str.replace(/\D/gi,&quot;&quot;);
}

=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top