A
Al Jones
This was originally posted in the VBScript forum, several of my other
questions have been vbscript related, one of the fine fellows there suggest
I might want to post it as well in the jscript group, so since I'm heading
toward staching these values in session vars I figured I'd toss it out here
as well..
I'm back with something that makes no sense to me .... as far as I can see
the three if statements are identical except for the input. One is the
regular phone, then cell phone and then the fax .....
function validForm( passform) {
<< other validation skipped >>
re = /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})$/
validPhone = re.exec(passForm.fldPhone.value);
if ( validPhone ) {
passForm.fldPhone.value = "(" + validPhone[1] + ") " + validPhone[2] +
"-" + validPhone[3];
}
else {
errList += " a valid phone number\n";
if (!hasError) {
passForm.fldPhone.focus();
hasError = true;
}
}
if ( passForm.fldCell.length > 0) {
recell = /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})$/
validCell = recell.exec(passForm.fldCell.value);
if ( validCell ) {
passForm.fldCell.value = "(" + validCell[1] + ") " + validCell[2] + "-"
+ validCell[3];
}
else {
errList += " if entered the cell must be a valid phone number\n";
if (!hasError) {
passForm.fldCell.focus();
hasError = true;
}
}
}
if ( passForm.fldFax.length > 0) {
refax = /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})$/
validFax = refax.exec(passForm.fldFax.value);
if ( validFax ) {
passForm.fldFax.value = "(" + validFax[1] + ") " + validFax[2] + "-" +
validFax[3];
}
else {
errList += " if entered the fax must be a valid phone number\n";
if (!hasError) {
passForm.fldFax.focus();
hasError = true;
}
}
}
<< handle the error and redirect to the next form >>
}
THey shouldbe identical since I copied the first one and made the requisit
changes for the cell and fax. However the output (as show in the session
variables into which they are stashed)
Session("svPersonPhone") = Request.Form("fldPhone")
Session("svPersonCell") = Request.Form("fldCell")
Session("svPersonFax") = Request.Form("fldFax")
show up as follows:
SVPERSONZIPCODE - 123451234
SVPERSONPHONE - (123) 123-1234
SVPERSONCELL - 4564564567 <<== notice not formatted ...
SVPERSONFAX - 7897987890
SVPERSONEMAIL -
initially the regular expressions were all just 're' then when I started
looking at this I changed them to 'recell' and 'refax' on the off chance
that there might be a funny in re-using a regular expression.
as always other comments are appreciated, but please also address this
issue. ((I know "picky, picky...."))
questions have been vbscript related, one of the fine fellows there suggest
I might want to post it as well in the jscript group, so since I'm heading
toward staching these values in session vars I figured I'd toss it out here
as well..
I'm back with something that makes no sense to me .... as far as I can see
the three if statements are identical except for the input. One is the
regular phone, then cell phone and then the fax .....
function validForm( passform) {
<< other validation skipped >>
re = /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})$/
validPhone = re.exec(passForm.fldPhone.value);
if ( validPhone ) {
passForm.fldPhone.value = "(" + validPhone[1] + ") " + validPhone[2] +
"-" + validPhone[3];
}
else {
errList += " a valid phone number\n";
if (!hasError) {
passForm.fldPhone.focus();
hasError = true;
}
}
if ( passForm.fldCell.length > 0) {
recell = /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})$/
validCell = recell.exec(passForm.fldCell.value);
if ( validCell ) {
passForm.fldCell.value = "(" + validCell[1] + ") " + validCell[2] + "-"
+ validCell[3];
}
else {
errList += " if entered the cell must be a valid phone number\n";
if (!hasError) {
passForm.fldCell.focus();
hasError = true;
}
}
}
if ( passForm.fldFax.length > 0) {
refax = /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})$/
validFax = refax.exec(passForm.fldFax.value);
if ( validFax ) {
passForm.fldFax.value = "(" + validFax[1] + ") " + validFax[2] + "-" +
validFax[3];
}
else {
errList += " if entered the fax must be a valid phone number\n";
if (!hasError) {
passForm.fldFax.focus();
hasError = true;
}
}
}
<< handle the error and redirect to the next form >>
}
THey shouldbe identical since I copied the first one and made the requisit
changes for the cell and fax. However the output (as show in the session
variables into which they are stashed)
Session("svPersonPhone") = Request.Form("fldPhone")
Session("svPersonCell") = Request.Form("fldCell")
Session("svPersonFax") = Request.Form("fldFax")
show up as follows:
SVPERSONZIPCODE - 123451234
SVPERSONPHONE - (123) 123-1234
SVPERSONCELL - 4564564567 <<== notice not formatted ...
SVPERSONFAX - 7897987890
SVPERSONEMAIL -
initially the regular expressions were all just 're' then when I started
looking at this I changed them to 'recell' and 'refax' on the off chance
that there might be a funny in re-using a regular expression.
as always other comments are appreciated, but please also address this
issue. ((I know "picky, picky...."))