js validation

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

js validation

Post by nincha »

okay, a number validation is <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> me off...im very bad at JS and cant find a way to distinguish a string from a number....If any one can help, it be very nice of yah...thnx


AND can any one find the error in this code, thnx

Code: Select all

onClick="

var Fcount       = 0 
var Formstatus  = true

while ((Fcount < document.forms&#1111;blah].elements.length) && (Formstatus))
   &#123;
     if (document.forms&#1111;blah].elements&#1111;Fcount].value == '''')
     &#123; 
        alert(''Please complete all fields.'')
        document.forms&#1111;blah].elements&#1111;Fcount].focus()
        Formstatus = false 
     &#125;
     Fcount ++
   &#125;
return Formstatus


 ">
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

why backslashes?

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html> 
	<head>
		<title>validating numbers with js-regex</title>
		<script type="text/javascript">
		<!--
			function myTest()
			&#123;
				var ex = /^\d+$/;
				var oi = document.getElementById("i1");
				if (ex.test(oi.value) == false)
					oi.style.color = "red";
				else
					oi.style.color = "";
			&#125;
		-->
		</script>
	</head>
	<body>
		<p>
			<label for="i1">digits only</label>
			<input type="text" id="i1" onKeyup="javascript:myTest();" />
		</p>
	</body>
</html>
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

What error message do you get?
Post Reply