![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | How do I create a mask for a phone #? Did this a while back, but I forgot how to do it again. I want to have the text box display (nnn)nnn-nnnn, either before or after the data is entered. bbb bbb bbbb or bbbbbbbbbb * b represents a blank or a space If we enter 682 777 3569 or 6827773569 or 682-777-3569 I want it to look like (682)777-3569. Appreciate the assistance. JZQ |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How do I create a mask for a phone #? "John Quinn" <JohnQuinn@xxxxxx> wrote in message news:78FA7F5A-3D40-4307-8F83-C6E8D5E726B7@xxxxxx Quote: > Did this a while back, but I forgot how to do it again. > > I want to have the text box display (nnn)nnn-nnnn, either before or after > the data is entered. > > bbb bbb bbbb or bbbbbbbbbb * b represents a blank or a space > > If we enter 682 777 3569 or 6827773569 or 682-777-3569 I want it to look > like > > (682)777-3569. > > Appreciate the assistance. > > JZQ followed by your own function to add the paretheses and the dash. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How do I create a mask for a phone #? "John Quinn" <JohnQuinn@xxxxxx> wrote in message news:78FA7F5A-3D40-4307-8F83-C6E8D5E726B7@xxxxxx Quote: > Did this a while back, but I forgot how to do it again. > > I want to have the text box display (nnn)nnn-nnnn, either before or after > the data is entered. > > bbb bbb bbbb or bbbbbbbbbb * b represents a blank or a space > > If we enter 682 777 3569 or 6827773569 or 682-777-3569 I want it to look > like > > (682)777-3569. > > Appreciate the assistance. the below code. It will handle the examples you gave, but not international numbers. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MsgBox PhoneMask("682 777 3569") MsgBox PhoneMask("6827773569") MsgBox PhoneMask("682-777-3569") Function PhoneMask(ByVal sPhone) With CreateObject("VBScript.RegExp") .Global = True .Pattern = "([^0-9])" 'Pattern to remove all non-digits sPhone = .Replace(sPhone, Empty) .Pattern = "(\d{3})(\d{3})(\d{4})" 'Pattern to format the digits PhoneMask = .Replace(sPhone, "($1) $2-$3") End With End Function '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
My System Specs![]() |
| | #4 (permalink) |
| | Re: How do I create a mask for a phone #? "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message news:%23NHw6vNeJHA.3776@xxxxxx Quote: > "John Quinn" <JohnQuinn@xxxxxx> wrote in message > news:78FA7F5A-3D40-4307-8F83-C6E8D5E726B7@xxxxxx Quote: >> Did this a while back, but I forgot how to do it again. >> >> I want to have the text box display (nnn)nnn-nnnn, either before or after >> the data is entered. >> >> bbb bbb bbbb or bbbbbbbbbb * b represents a blank or a space >> >> If we enter 682 777 3569 or 6827773569 or 682-777-3569 I want it to look >> like >> >> (682)777-3569. >> >> Appreciate the assistance. > If you don't mind instantiating the 'VBScript.RegExp' object, you can try > the below code. It will handle the examples you gave, but not > international numbers. > > '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > MsgBox PhoneMask("682 777 3569") > MsgBox PhoneMask("6827773569") > MsgBox PhoneMask("682-777-3569") > > Function PhoneMask(ByVal sPhone) > With CreateObject("VBScript.RegExp") > .Global = True > .Pattern = "([^0-9])" 'Pattern to remove all non-digits > sPhone = .Replace(sPhone, Empty) > .Pattern = "(\d{3})(\d{3})(\d{4})" 'Pattern to format the digits > PhoneMask = .Replace(sPhone, "($1) $2-$3") > End With > End Function > '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ than ten? /Al |
My System Specs![]() |
| | #5 (permalink) |
| | Re: How do I create a mask for a phone #? "Al Dunbar" <alandrub@xxxxxx> wrote in message news:uDmi8pQeJHA.3856@xxxxxx Quote: > > "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message > news:%23NHw6vNeJHA.3776@xxxxxx Quote: >> "John Quinn" <JohnQuinn@xxxxxx> wrote in message >> news:78FA7F5A-3D40-4307-8F83-C6E8D5E726B7@xxxxxx Quote: >>> Did this a while back, but I forgot how to do it again. >>> >>> I want to have the text box display (nnn)nnn-nnnn, either before or >>> after >>> the data is entered. >>> >>> bbb bbb bbbb or bbbbbbbbbb * b represents a blank or a space >>> >>> If we enter 682 777 3569 or 6827773569 or 682-777-3569 I want it to look >>> like >>> >>> (682)777-3569. >>> >>> Appreciate the assistance. >> If you don't mind instantiating the 'VBScript.RegExp' object, you can >> try the below code. It will handle the examples you gave, but not >> international numbers. >> >> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> MsgBox PhoneMask("682 777 3569") >> MsgBox PhoneMask("6827773569") >> MsgBox PhoneMask("682-777-3569") >> >> Function PhoneMask(ByVal sPhone) >> With CreateObject("VBScript.RegExp") >> .Global = True >> .Pattern = "([^0-9])" 'Pattern to remove all non-digits >> sPhone = .Replace(sPhone, Empty) >> .Pattern = "(\d{3})(\d{3})(\d{4})" 'Pattern to format the digits >> PhoneMask = .Replace(sPhone, "($1) $2-$3") >> End With >> End Function >> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Interesting. What will result if the user inputs either more or fewer > digits than ten? remove non-digits with fewer than 10 (no formatting). Below is a small revision that should handle a few more conditions. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MsgBox PhoneMask("682 777 3569") MsgBox PhoneMask("6827773569") MsgBox PhoneMask("682-777-359") MsgBox PhoneMask("6827") MsgBox PhoneMask("US+01-682-777-3569") MsgBox PhoneMask("US+01-6827773569x1234") MsgBox PhoneMask("1-682-777-3569 Ext 1234") Function PhoneMask(ByVal sPhone) With CreateObject("VBScript.RegExp") .Global = True .Pattern = "([^0-9])" 'Pattern to remove all non-digits sPhone = .Replace(sPhone, Empty) & String(10, "?") .Pattern = "[01]*([\d?]{1,3})([\d?]{1,3})([\d?]{1,4}).*" 'Format PhoneMask = .Replace(sPhone, "($1) $2-$3") End With End Function '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
My System Specs![]() |
| | #6 (permalink) |
| | Re: How do I create a mask for a phone #? In microsoft.public.scripting.vbscript message <ui5sNdNeJHA.5344@xxxxxx NGP05.phx.gbl>, Sat, 17 Jan 2009 20:10:45, "Pegasus (MVP)" <I.can@xxxxxx> posted: Quote: > >"John Quinn" <JohnQuinn@xxxxxx> wrote in message >news:78FA7F5A-3D40-4307-8F83-C6E8D5E726B7@xxxxxx Quote: Quote: >> I want to have the text box display (nnn)nnn-nnnn, either before or after >> the data is entered. Quote: >One way is to use the "replace" function to remove all spaces and dashes, >followed by your own function to add the paretheses and the dash. But the OP needs to be aware that not all telephones in North America necessarily have numbers which fit that ten-digit pattern. -- (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME. Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links. Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036) Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036) |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Vista Phone Dialer can't dial phone rules correct | Vista General | |||
| Vista Phone Dialer can't dial phone rules correct | Vista General | |||
| Unable to create dial-up connections or enter phone properties | Vista hardware & devices | |||
| To mask the email adress | Vista mail | |||
| Where can I see my IP and net mask? | Vista networking & sharing | |||