Page 1 of 1

js validation

Posted: Sun Apr 20, 2003 12:05 pm
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


 ">

Posted: Sun Apr 20, 2003 8:50 pm
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>

Posted: Mon Apr 21, 2003 6:24 am
by patrikG
What error message do you get?