+ Reply to Thread
Results 1 to 3 of 3

Input Mask for TextBox

  1. #1
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Input Mask for TextBox

    I have a TextBox for which I want to control the user input for UK postcodes, in the following format "[A-Z][A-Z][0-9][0-9]<space>[0-9][A-Z][A-Z]"

    I have seen numerous variations of code which apparently does this but I can't it to work, usually around..

    Please Login or Register  to view this content.
    I've tried the above in the TextBoxPostcode_Change(), TextBoxPostcode_AfterUpdate(), and UserForm_Initialize() events to no avail. I've also seen the above string represented as "LL00 0LL"

    Is there an easy way to do this?

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Input Mask for TextBox

    I posted a solution for this a week ago, but now it's gone. Here's another one:
    Please Login or Register  to view this content.
    Note that the code automatically inputs the space for you.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Input Mask for TextBox

    Andy, do you want all valid UK postcodes or just the ones that confirm to that format? There are plenty of valid ones that are not in the format you describe, for example S75 2DY, EC1V 7EB, GIR 0AA. If you want all valid ones, then unfortunately Paul's suggestion won't work - if you don't then great

    Here's a function with the official regular expression - note that all letters must be capitals and there must be a space:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1