Telephone format in text control - InfoPath Dev
in

InfoPath Dev

Telephone format in text control

Last post 04-11-2015 05:29 PM by djm50. 31 replies.
Page 1 of 3 (32 items) 1 2 3 Next >
Sort Posts: Previous Next
  • 10-08-2008 07:04 PM

    Telephone format in text control

    Is there a way to configure a text box control to format numbers entered into telephone format (xxx) yyy-zzzz?

  • 10-08-2008 09:46 PM In reply to

    Re: Telephone format in text control

    Hello and welcome to the board!

    Try the following steps:

    1. Add a rule to your textbox control with the following conditions (make sure to select "and" operator):
        a. field "does not match pattern" Phone number
        b. the expression: string-length(translate(., "()- ", "")) = 10
        c. the expression: string-length(translate(., "()- 0123456789", "")) = 0

    2. Add action to the rule:
        a. Set a field's value
        b. Select your textbox field
        c. Insert formula for the value (click the fx button): concat("(", substring(translate(., "()- ", ""), 1, 3), ") ", substring(translate(., "()- ", ""), 4, 3), "-", substring(translate(., "()- ", ""), 7, 4))

     

    That should work like a charm!

    Good luck!

    Mel Clemente
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

    Filed under:
  • 10-08-2008 10:22 PM In reply to

    Re: Telephone format in text control

    Worked like a champ..thanks!

  • 10-08-2008 11:06 PM In reply to

    Re: Telephone format in text control

    Yey!

    Glad it did! :)

    Mel Clemente
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 04-29-2010 10:33 AM In reply to

    Re: Telephone format in text control

    I've noticed that sometimes people will input a number as 555.555.5555, and the functions above don't work as they should.  To get around this, modify it just a bit:

    1.        Add a rule to your textbox control with the following conditions (make sure to select "and" operator):
        
    a.        field "does not match pattern" Phone number
        
    b.        the expression: string-length(translate(., "()-. ", "")) = 10
        
    c.        the expression: string-length(translate(., "()-. 0123456789", "")) = 0 2.        Add action to the rule:
        
    a.        Set a field's value
        
    b.        Select your textbox field
        
    c.        Insert formula for the value (click the fx button): concat("(", substring(translate(., "()-. ", ""), 1, 3), ") ", substring(translate(., "()-. ", ""), 4, 3), "-", substring(translate(., "()-. ", ""), 7, 4))

     

  • 09-10-2010 09:23 AM In reply to

    Re: Telephone format in text control

    This is Great.  Thanks for posting.

     I was curious, how would you modify it to accomodate country codes.  Like +1 (800) 555-1212 

  • 02-25-2011 05:27 AM In reply to

    Re: Telephone format in text control

    so when you setup the text box is it a string or whole number, is there a need to set the max amount of characters allowed?

     and this would be a validation

  • 03-07-2011 01:42 PM In reply to

    Re: Telephone format in text control

    When I set mine up I did it as a text (String) so that users could be able to enter () and - if they wanted. Then I set the validation up to only allow phone number pattern and told the user in a pop up that only 10 numbers could be entered. If you really want the brake down I can give it out there, but try this first and messing around with the validation rules! Its really up to what you want it to do. If you only want it to accept numbers and users would understand that, then that is the route I would go. We had to go this route becuase so many users its hard to know that all of them would know to enter just numbers. Good luck.

  • 03-10-2011 10:52 AM In reply to

    • nithra
    • Not Ranked
    • Joined on 03-09-2011
    • Posts 3

    Re: Telephone format in text control

    Hi,

     Thanks for your posting.I need a help in setting formatting elements in text box.I need a mask in text box which should be in this format (_____-____-___-____-____) so that user can enter specific text within tthis.

    Soonest reply will be so helpful.

    Nithra

  • 01-17-2013 11:09 AM In reply to

    Re: Telephone format in text control

    Mel Balsamo:
    c. Insert formula for the value (click the fx button): concat("(", substring(translate(., "()- ", ""), 1, 3), ") ", substring(translate(., "()- ", ""), 4, 3), "-", substring(translate(., "()- ", ""), 7, 4))
    Mel, How would you write a formula that accepts both (000) 000-0000 and 0-000-000-0000 formats? I'd like for my users to be able to insert both phone patterns into the text box control. Thanks, KT
  • 01-21-2013 01:00 AM In reply to

    Re: Telephone format in text control

    wow the complete code. thanks for sharing. it helped me a lot in solving my problem though
  • 11-26-2013 12:21 PM In reply to

    Re: Telephone format in text control

    I am trying to do the following formatting. I understand what is being done but I cant seem to get it to work. I need users to type 32 characters in to a field and then it automatically formats it like this: xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx any help please?
  • 11-28-2013 11:05 AM In reply to

    Re: Telephone format in text control

    Hi,

    I attached a sample XSN that does what you want. Check out the rule in field1 - you'll see that it first checks if the length is 32 characters, and then it builds the string using the formula:

    concat(substring(., 1, 2), ":", substring(., 3, 2), ":", substring(., 5, 2), ":", substring(., 7, 2), ":", substring(., 9, 2), ":", substring(., 11, 2), ":", substring(., 13, 2), ":", substring(., 15, 2), ":", substring(., 17, 2), ":", substring(., 19, 2), ":", substring(., 21, 2), ":", substring(., 23, 2), ":", substring(., 25, 2), ":", substring(., 27, 2), ":", substring(., 29, 2), ":", substring(., 31, 2))

     Hope that helps!

    Mel Clemente
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 12-11-2013 07:42 AM In reply to

    Re: Telephone format in text control

    I have this in use, but if a user enters only their extension (Ex. 75078), this is accepted in the field and will appear as (750) 78. How can I make it required that 10 digits MUST be entered?

  • 12-11-2013 04:45 PM In reply to

    Re: Telephone format in text control

    You can add a data validation rule that checks the character count, for example: string-length(my:phoneNumber) < 10
    Mel Clemente
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

Page 1 of 3 (32 items) 1 2 3 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.