Brazilian phone number format

  1. #1

    Brazilian phone number format

    In brazil we have both 8-digit and 9-digit format, so i would like to provide an example of using InputMask to accomplish this requirement
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <script type="text/javascript">
            var ProcessMask = function (item, newValue, oldValue) {
                var newMask = null;
                var eightDigitFormat = "(~~) ~999-9999?9";
                var nineDigitFormat = "(~~) ~9999-9999";
    
                if (item.inputMask.getUnmaskedValue().length < 11) {
                    newMask = eightDigitFormat;
                }
                else {
                    newMask = nineDigitFormat;
                }
    
                if (item.inputMask.mask != newMask) {
    
                    item.suspendEvents();
    
                    item.inputMask.setMask(newMask);
    
                    item.resumeEvents();
                }
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:TextField FieldLabel="Brazilian Phone" AllowBlank="false" runat="server">
            <Plugins>
                <ext:InputMask Mask="(~~) ~999-9999?9" ClearWhenInvalid="false" runat="server">
                    <MaskSymbols>
                        <ext:MaskSymbol Name="~" Regex="[1-9]" />
                    </MaskSymbols>
                </ext:InputMask>
            </Plugins>
            <Listeners>
                <Change Fn="ProcessMask" />
            </Listeners>
        </ext:TextField>
    </body>
    </html>


    Daniil, if you have nothing to add, please mark this thread as closed.
    Last edited by RaphaelSaldanha; Jan 01, 2015 at 6:27 AM.
  2. #2
    Raphael, thank you for sharing!

    I've moved the thread to the Examples and Extras forum.
  3. #3
    Thank you Daniil.

Similar Threads

  1. Replies: 0
    Last Post: Dec 09, 2013, 12:47 PM
  2. FORMAT NUMBER ON A GRIDPANEL
    By marcmvc in forum 1.x Help
    Replies: 2
    Last Post: Feb 21, 2011, 9:23 AM
  3. [CLOSED] Number Format
    By majestic in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 23, 2011, 3:57 AM
  4. How to format a number with 3 decimal
    By NishaLijo in forum 1.x Help
    Replies: 1
    Last Post: Nov 24, 2010, 5:44 AM
  5. How to validate Fax, Phone number and zip code?
    By flormariafr in forum 1.x Help
    Replies: 5
    Last Post: Jan 22, 2010, 3:46 PM

Posting Permissions