Results 1 to 4 of 4

Thread: Ext.ux.UsPhoneField Us Phone Number Field Extension

  1. #1
    Ext JS Premium Member vishalg's Avatar
    Join Date
    Sep 2007
    Location
    Los Angeles, CA
    Posts
    75
    Vote Rating
    0
      0  

    Default Ext.ux.UsPhoneField Us Phone Number Field Extension

    This extension will provide a field that validates and formats a US Phone Number.

    To test drive, drop the directory in your ext/examples/ directory and open ext/example/usphonenumber/usphonenumber.html

    Updated: 04/29/2010
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by vishalg; 29 Apr 2010 at 3:46 PM. Reason: Patched for bug in thread # 2

  2. #2
    Ext User Perez's Avatar
    Join Date
    Dec 2009
    Posts
    2
    Vote Rating
    0
      0  

    Default

    Addressing the string as an Array will return undefined in Microsoft Internet Explorer 6.0. You can modify the following for it to work in ie:

    Code:
    beforeBlur : function(){
            if( this.outputFormat ) {
                var rawValue = this.getRawValue();
                if (rawValue && rawValue.length >= 10) {
                    var normalizedValue = "";
                    var digitRegEx = /\d/;
                    for (i = 0; i < rawValue.length; i++) {
                        if (rawValue.substr(i,1).match(digitRegEx)) {
                            normalizedValue = normalizedValue.concat(rawValue.charAt(i));
                        }
                    }
                    if( normalizedValue.length == 10 ) {
                        this.setValue(
                            String.format(  this.outputFormat,
                                normalizedValue.charAt(0),
                                normalizedValue.charAt(1),
                                normalizedValue.charAt(2),
                                normalizedValue.charAt(3),
                                normalizedValue.charAt(4),
                                normalizedValue.charAt(5),
                                normalizedValue.charAt(6),
                                normalizedValue.charAt(7),
                                normalizedValue.charAt(8),
                                normalizedValue.charAt(9)
                            )
                        );
                    }
                }
            }
        }

  3. #3
    Ext JS Premium Member vishalg's Avatar
    Join Date
    Sep 2007
    Location
    Los Angeles, CA
    Posts
    75
    Vote Rating
    0
      0  

    Default

    Thanks Perez!,

    I have fixed that and uploaded a new extension in my original post.

    Quote Originally Posted by Perez View Post
    Addressing the string as an Array will return undefined in Microsoft Internet Explorer 6.0. You can modify the following for it to work in ie:

    Code:
    beforeBlur : function(){
            if( this.outputFormat ) {
                var rawValue = this.getRawValue();
                if (rawValue && rawValue.length >= 10) {
                    var normalizedValue = "";
                    var digitRegEx = /\d/;
                    for (i = 0; i < rawValue.length; i++) {
                        if (rawValue.substr(i,1).match(digitRegEx)) {
                            normalizedValue = normalizedValue.concat(rawValue.charAt(i));
                        }
                    }
                    if( normalizedValue.length == 10 ) {
                        this.setValue(
                            String.format(  this.outputFormat,
                                normalizedValue.charAt(0),
                                normalizedValue.charAt(1),
                                normalizedValue.charAt(2),
                                normalizedValue.charAt(3),
                                normalizedValue.charAt(4),
                                normalizedValue.charAt(5),
                                normalizedValue.charAt(6),
                                normalizedValue.charAt(7),
                                normalizedValue.charAt(8),
                                normalizedValue.charAt(9)
                            )
                        );
                    }
                }
            }
        }

  4. #4
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710
    Vote Rating
    6
      0  

    Default

    Thanks, was needing this!

    However, I think you need to change your regex expression to the following to account for cases when you have a phone number field that is not required. As it is, this will invalidate a blank phone number.

    Code:
        regex : /^(([(]?\d{3}[)]?[ ]*[-]?[ ]*)(\d{3}[ ]*[-]?[ ]*)(\d{4})[ ]*)*$/,
    Thank again for the extension

Posting Permissions

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