What is the error in this code:
_______________________________
var X="Hi [ ARE HOW";
if(X.match('[')==('['))
{
alert("please Do not use [ ");
return;
}
Printable View
What is the error in this code:
_______________________________
var X="Hi [ ARE HOW";
if(X.match('[')==('['))
{
alert("please Do not use [ ");
return;
}
hello,
i don't know what match is but this is what I would do
specify a list of bad chars and then just test your string against each one (tested in IE6 only)
i put it in a textbox
bsw2112Code:<html>
<head>
<script>
var badChars = new Array("@", "#", "[", "]");
function validateString(frm1) {
var valString = frm1.boo.value;
for (ndx = 0; ndx<badChars.length;ndx++)
{
for (ndx2=0;ndx2< valString.length; ndx2++)
{
if (valString.charAt(ndx2) == badChars[ndx]) {
alert("error");
frm1.boo.focus;
return false; }
}
}
return true;
}
</script>
</head>
<body>
<form name = foo action = "blank.cgi" onSubmit= "return validateString(this)" method=POST>
<input type = "text" name = "boo"><br><br>
<input type = "submit">
</form>
</body>
</html>
I may be totally wrong here, but isn't match a RegExpr thing? If it is I don't think you are specifying X as a regular expression. But as I say, I could be way off :p
In this code:
____________
var X="Hi [ ARE HOW";
if(X.match('[')==('['))
{
alert("please Do not use [ ");
return;
}
___________
when I replace [ with any other letter or number the code work with out problem. so [ is the cause of this problem.
match is used to check regular expressions against a string
http://www.devguru.com/Technologies/...ing_match.html
So it is a RegExpr? [ and ] are used to group strings aren't they? So you should be able to escape them with \[ and \] shouldn't you?
How can I right this code in right way?
______________________
var X="Hi [ ARE HOW";
if(X.match('[')==('['))
{
alert("please Do not use [ ");
return;
}
______________________
Not sure, what I said didn't work after all :o