Click to See Complete Forum and Search --> : Finding the Unterminated...


EndEffect
01-23-2003, 09:22 AM
Im relatively new to coding javascript as I am a VBScript devotee. I have come across a bit of code I wish to use to validate a phone number. Doesnt seem that hard at all, but when I run the code I came up with, I get an "Unterminated String Constant" error. I have tried to find it, but it remains invisible to me:

Data supplied: "(215) 555-1212"

Code to check a valid phone number:

if (e.phoneNumber) {
num = e.value;
num = stripChar(num, " ");
num = stripChar(num, "-");
num = stripChar(num, "+");
num = stripChar(num, "/");
num = stripChar(num, "\");
num = stripChar(num, "(");
num = stripChar(num, ")");

if (!isNumber(num)) {
invalid_phoneNumber = true;
}
else {
if (num.length < 10) {
invalid_phoneNumber = true;
}
}
}

Referenced code to strip Characters:

function stripChar(sValue, sChar) {
var i, tempChar, buildString;
buildString = ""
for (var i=0; i<sValue.length; i++) {
tempChar = sValue.charAt(i);
if (tempChar != sChar) {
buildString = buildString + tempChar;
}
}
return buildString;
}

Referenced code to check if string is numerical:

function isNumber(value) {
for (var i=0; i < value.length; i++) {
a = parseInt(value.charAt(i));
if (isNaN(a)) {
return false;
break;
}
}
return true;
}

Thank you all in advance for your help!

Charles
01-23-2003, 09:30 AM
num = stripChar(num, "\") should be, methinks, num = stripChar(num, "\\").

EndEffect
01-23-2003, 09:39 AM
WOW!

Thank you for your prompt reply. It worked beautifully. Totally forgot about having to let the code know I'm referring to the character itself and not a function or switch!

Sometimes you lose your mind in the code!

I will definately come back here for help! Thank you all again!