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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unescape comma 1

Status
Not open for further replies.

jianhua

Programmer
Jun 22, 2001
55
US
Hi,

I tried to validate a text field to see whether the string contains a comma or not. If there is no comma in that string, alert box appears. Now the problem is that I cannot unescape comma. My code is as follows:

function upd_info(f){
var err = true;
for (var i=0; i < f.elementname.value.toString().length; i++){
var oneChar = f.elementname.value.toString().charAt(i);
if (oneChar == &quot;,&quot;){ //also tried if (oneChar == unescape(&quot;%2C&quot;))
err = false; break; }
}
if (err == true){
alert(&quot;You must have a comma to separate the last name and the first name.&quot;);
return(false);
}
return(true);
}

Thanks in advance...
-J
 
Why not use:
function upd_info(f){
if(f.elementname.value.indexOf(&quot;,&quot;)>-1){
alert(&quot;You must have a comma to separate the last name and the first name.&quot;);
return false;
}
return true;
} Adam
 
Thanks Adam!!!

It's working... and I changed it to
if(f.elementname.value.indexOf(&quot;,&quot;) == -1)

Thanks again!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top