View Full Version : Ext.ux.UsPhoneField Us Phone Number Field Extension
vishalg
26 Mar 2010, 1:47 PM
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
Perez
29 Apr 2010, 1:37 PM
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:
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)
)
);
}
}
}
}
vishalg
29 Apr 2010, 3:47 PM
Thanks Perez!,
I have fixed that and uploaded a new extension in my original 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:
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)
)
);
}
}
}
}
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.
regex : /^(([(]?\d{3}[)]?[ ]*[-]?[ ]*)(\d{3}[ ]*[-]?[ ]*)(\d{4})[ ]*)*$/,
Thank again for the extension :)
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.