MindCrafter
06-29-2004, 11:45 PM
Okay its late and I've run out of Jolt Cola...
I have a stock javascript scriptlet (shown below) that I use to validate both International and US phone number form fields.
Below are the two validation RegEpressions that I have used in the past.
RegExpr
International
/^x\s*[0-9]{5}$)|(^(\([1-9][0-9]{2}\)\s)?[1-9][0-9]{2}-[0-9]{4}(\sx\s*[0-9]{5})?$/
and
US (###) ###-####
/^((\(?[1-9][0-9][0-9]\)?)?\s?[1-9][0-9][0-9]\s?\d{4})?$/
Problem is, neither Regexp syntax are working in a ColdFusionMX webpage.
Validation Code
function chkPhone(sFieldName,sFieldValue){
var regExpr = /^((\(?[1-9][0-9][0-9]\)?)?\s?[1-9][0-9][0-9]\s?\d{4})?$/;
if (!regExpr.test(sFieldValue)){
alert('Invalid phone number format detected.\nPlease enter a valid phone number. e.g. \(###\) ###\-#### (123) 456\-7890');
document.frmCreateNewUser.elements[sFieldName].className='DataEntryFieldsErr';
document.frmCreateNewUser.elements[sFieldName].value='\(###\) ###\-####';
document.frmCreateNewUser.elements[sFieldName].focus;
}else{
document.frmCreateNewUser.elements[sFieldName].className='DataEntryFieldsEnabled';
}
}
Form Field Code:
<input type="text"
id="txtWorkPhone"
name="txtWorkPhone"
class="DataEntryFieldsEnabled"
tabindex="6"
onchange="if(this.value!='\(###\) ###\-####')
chkPhone(this.name,this.value);"
onFocus="this.className='FieldHighlight';ClearHighlight(this.name);"
value="(###) ###-####"
maxlength="15" />
A test copy of the form can be viewed at
http://www.mindcrafter.com/testform1.cfm (http://http://www.mindcrafter.com/testform1.cfm)
Any Suggestions?
MindCrafter
DaleM@MindCrafter.com
I have a stock javascript scriptlet (shown below) that I use to validate both International and US phone number form fields.
Below are the two validation RegEpressions that I have used in the past.
RegExpr
International
/^x\s*[0-9]{5}$)|(^(\([1-9][0-9]{2}\)\s)?[1-9][0-9]{2}-[0-9]{4}(\sx\s*[0-9]{5})?$/
and
US (###) ###-####
/^((\(?[1-9][0-9][0-9]\)?)?\s?[1-9][0-9][0-9]\s?\d{4})?$/
Problem is, neither Regexp syntax are working in a ColdFusionMX webpage.
Validation Code
function chkPhone(sFieldName,sFieldValue){
var regExpr = /^((\(?[1-9][0-9][0-9]\)?)?\s?[1-9][0-9][0-9]\s?\d{4})?$/;
if (!regExpr.test(sFieldValue)){
alert('Invalid phone number format detected.\nPlease enter a valid phone number. e.g. \(###\) ###\-#### (123) 456\-7890');
document.frmCreateNewUser.elements[sFieldName].className='DataEntryFieldsErr';
document.frmCreateNewUser.elements[sFieldName].value='\(###\) ###\-####';
document.frmCreateNewUser.elements[sFieldName].focus;
}else{
document.frmCreateNewUser.elements[sFieldName].className='DataEntryFieldsEnabled';
}
}
Form Field Code:
<input type="text"
id="txtWorkPhone"
name="txtWorkPhone"
class="DataEntryFieldsEnabled"
tabindex="6"
onchange="if(this.value!='\(###\) ###\-####')
chkPhone(this.name,this.value);"
onFocus="this.className='FieldHighlight';ClearHighlight(this.name);"
value="(###) ###-####"
maxlength="15" />
A test copy of the form can be viewed at
http://www.mindcrafter.com/testform1.cfm (http://http://www.mindcrafter.com/testform1.cfm)
Any Suggestions?
MindCrafter
DaleM@MindCrafter.com