Forum Moderators: open

Message Too Old, No Replies

Validation help

How to call a function from another function

         

cspitzig

9:38 pm on Oct 9, 2003 (gmt 0)

10+ Year Member



This is the same question that was posted yesterday.
I had some assistance from DrDoc, but I can't seem to get the syntax to work, and when I put if statements into the functions I create endless loops.

Colleen

<script Language="JavaScript" type="text/javascript">
<!--
function validateEmpty(objcontrol)
{
var result = true;
//alert("hello world");
if (objcontrol.value == "" ¦¦ objcontrol == null){

objcontrol.focus();
objcontrol.select();
result = false;
}
return result;
}

function validateNumber(objcontrol)
{
var ValidChars = "0123456789.";
var result = true;
var Char;
var mystring = objcontrol.value

// alert(mystring.length);
for (i = 0; i < mystring.length && result == true; i++)
{
Char = mystring.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{

alert("Please enter numbers only");
objcontrol.focus();
objcontrol.select();
result = false;
}
}
return result;
}
-->

</script>

RonPK

10:01 pm on Oct 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Colleen, try this:

<script type="text/javascript">
// note that language=javascript is deprecated
<!--
function validate(objcontrol)
{
var mystring = objcontrol.value
// first check
if (mystring == "" ¦¦ objcontrol == null){ // change the ¦¦ into solid pipes
alert("Please enter something");
objcontrol.focus();
objcontrol.select();
return false;
}

// second check, with some nice little regular expression pattern matching
var numbersOnly = /\d+/
if (!mystring.match(numbersOnly))
{
alert("Please enter numbers only");
objcontrol.focus();
objcontrol.select();
return false;
}

// we passed all the tests, so:
return true;
}
-->

</script>

<form name="searchResult2" action="../donewPermitSearch.asp" method=POST onSubmit="return validate(this.PermitNO)" >

RonPK

10:12 pm on Oct 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sorry,
var numbersOnly = /\d+/
shoudl be
var numbersOnly = /^\d+$/