Results 1 to 2 of 2

Thread: JavaScript Form Validation

  1. #1
    Join Date
    May 2011
    Posts
    7

    Post JavaScript Form Validation

    Hi, I'm new to the forums, and web design/development. Anyway, I am trying to write a JS that validates a form... I'm kind of frustrated with one part of it...

    HTML Code:
    <tr><td class="alignRight">Enter Age</td><td class="alignLeft"><input type="text" name="age" /></td></tr>
    I'm trying to check document.myForm.age and make sure that no characters other than numbers are in the field, that the value is no greater than 150 and no less than 13. Here's what I've come up with:

    Code:
    if((document.myForm.age.test([1-9]))==true){//my problem is here!
    
    		if((document.myForm.age.value)>(150)){
    
    			alert("Come on... no one's that old!");
    
    			return false;
    
    		}
    
    		if((document.myForm.age.value)<(13)){
    
    			alert("Sorry, you're too young to have an account!");
    
    			return false;
    
    		}
    
    	}else{
    
    		alert("You put letters in the age field.");
    
    		return false;
    
    	}
    }
    All of it works... except for the first line. Can anyone tell me how they check text for numbers? Thanks!

  2. #2
    Join Date
    Apr 2011
    Posts
    110

Similar Threads

  1. simple javascript validation for a signup form?
    By c_martini in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 25 Mar 2010, 03:07 PM

Posting Permissions

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