Click to See Complete Forum and Search --> : Validate user input


Nimisha
06-12-2003, 02:13 AM
Hi Dave

I'm back with the same problem well almost.


I did create function which validate that there are no meta tags i.e. "<" or ">" being inserted by the user into the text box. I call this function on the onkeyup of the text box. The function gets called and works fine if the meta tag is the first character in the text box, but if the user enters some text and then enters either < or > character, the functions doesnot do anything.

function CheckAnyMetaTagCharacters()
{
var sName;
var sContents;

sName = document.frmContact.txtTagName ;
if (sName.value == "<" || sName.value == ">" || sName.value == "<>" )
{
alert ("NO '<' or '>' allowed");
sName.focus();
sName.select();
return false;
}


}

<input type="text" name="txtTagName" width="100%" maxLength="255" onkeyup ="return CheckAnyMetaTagCharacters()" size="50">

Thoughts/help will be greatly appreciated.
Ta
Nimisha

Gollum
06-12-2003, 02:47 AM
I could suggest a couple of mods...

change your function so that it accepts a single argument...

funcion CheckAnyMetaTagCharacters(oInput)
{

// this way you have more direct access to the input field...
var sValue = oInput.value;

// then use regular expressions to find < or > characters anywhere in the input field...
if ( sValue.search(/[<>]/) != -1 )
{
alert, etc.
}
return true;
}


your input field becomes...
<input type="text" name="txtTagName" width="100%" maxLength="255" onkeyup ="return CheckAnyMetaTagCharacters(this)" size="50">

Nimisha
06-12-2003, 03:32 AM
Hi Gollum

Ta very much. You've hust made me happy bunny :D

Nimisha