Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

the "=" sign

Status
Not open for further replies.

shmil

Technical User
Apr 22, 2005
1
GB
I have this code:
Code:
var valid = "abcdefghijklmnopqrstuvwxyz0123456789-.:?&/"
var ok = "yes";
var temp;
for (var i=0; i < document.m.site_url.value.length; i++) {
temp = &quot;&quot; + document.m.site_url.value.substring(i, i+1);
if (valid.indexOf(temp) == &quot;-1&quot;) ok = &quot;no&quot;;
}
if (ok == &quot;no&quot;) {
alert(&quot;not good&quot;);
document.m.site_url.focus();
document.m.site_url.select();
return false;
   }
but when I add the &quot;=&quot; sign to the valid parameter I get an error.
Why would the = sign won't work?
Thanks.
 
To clean this up a bit, make sure to take into account capital letters, and add a backslash to escape the equal sign:

function validchars()
{
var validchar = &quot;abcdefghijklmnopqrstuvwxyz0123456789-.:?&/\=&quot;;
var onestring=document.m.site_url.value.toLowerCase();

for (var oi=0;oi<onestring.length;oi++)
{
var onechar=onestring.charAt(oi);
if (validchar.indexOf(onechar) == -1)
{
alert(&quot;Invalid character: &quot; + onechar);
document.m.site_url.focus();
document.m.site_url.select();
return false;
}
}
return true;
}

I didn't try this myself, so don't know what the problem with the equal sign would be in the original code. The code I wrote is the kind of function I use. I'm sure someone more familiar with regular expressions can give you something using them that's shorter, but more cryptic if you're not familiar with them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top