|
-
Jun 6th, 2005, 06:11 PM
#1
Thread Starter
Addicted Member
Javascript indexof problems
Hey, i'm having some problems with the javascript indexof function.
I have this:
Code:
function checkinvalid() {
var cde, def
cde = document.getElementById('username');
def = document.getElementById('password');
if (cde.value.indexof == "<"||def.value.indexof == "<"||cde.value.indexof == ">"||def.value.indexof == ">") {
alert("The < or > character cannot be used");
return false;
}else{
return true;
}}
Its returning true though :S I cant figure out why. I've tried escaping the < and > but its still not working. Anyone got any suggestions please??
Thanks, BIOSTALL
-
Jun 6th, 2005, 06:44 PM
#2
Re: Javascript indexof problems
Try this:
Code:
function checkinvalid() {
var cde, def
cde = document.getElementById('username');
def = document.getElementById('password');
if ((cde.value.indexOf("<") > 0) || (def.value.indexOf("<") > 0) || (cde.value.indexOf(">") > 0) || (def.value.indexOf(">") > 0)){
window.alert("The < or > character cannot be used");
return false;
}
else{
return true;
}}
Cheers,
RyanJ
-
Jun 7th, 2005, 06:42 AM
#3
Thread Starter
Addicted Member
Re: Javascript indexof problems
Cheers, code works a treat I just had to change the 0 to -1 so that it piked it up if > or < was the first or only character
Thanks again, BIOSTALL
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|