Print Page | Close Window

Javascript form validation

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Web Design Discussion
Forum Description: Discussion on web design and development subjects.
URL: https://forums.webwiz.net/forum_posts.asp?TID=14986
Printed Date: 29 March 2026 at 10:24am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Javascript form validation
Posted By: ub3rl337ch3ch
Subject: Javascript form validation
Date Posted: 09 May 2005 at 1:55am

For the most part validation is simple for me, but i'm wondering if there is a way to determine if a field contains only numbers. I need to check that someone hasn't entered their phone number as 82o1r90 or something like that.




Replies:
Posted By: dj air
Date Posted: 09 May 2005 at 7:02am
try this

function validate(field) {
var valid = "0123456789"
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Invalid entry!  Only numbers are accepted!");
field.focus();
field.select();
   }
}

and use the below to use the above

<input type=text name="entry" onBlur="validate(this)">



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net