Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    RegExpr Conundrum

    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
    Any Suggestions?

    MindCrafter
    DaleM@MindCrafter.com

  • #2
    New Coder
    Join Date
    Jun 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Figured it out

    Well, I went upstairs had a PBJ and a large glass of milk...

    Wnen I typed the RegExpr, I goofed.


    Original Expressions
    /^((\(?[1-9][0-9][0-9]\)?)?\s?[1-9][0-9][0-9]\s?\d{4})?$/


    Fixed Expression
    /^((\([1-9][0-9][0-9]\))\s[1-9][0-9][0-9]\-\d{4})$/

    Since I want to force the area code I just removed the question marks. Also I had a space escape character instead of a dash separating the first 3 and last 4 numeral in the phone number.

    Guess I better update my DW snippets!

    MindCrafter
    www.mindcrafter.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •