Genesys Cloud - Main

 View Only

Sign Up

  • 1.  UK Postcode regex

    Posted yesterday

    I am trying to find the regex to use in a bot flow that validates a UK postcode entered.

    Using 'M15 4FN' as an example, when I speak it, the bot hears 'M15 four FN' and passing that through the below regex fails validation.

    \b[a-z]{1,2}[0-9]{1,2}[0-9]{1}[a-z]{2}\b

    Have tried various AI suggested options but to no avail.

    Does anyone have the correct regex we should be using?


    #ArchitectandDesign

    ------------------------------
    Tim Speakman
    Tech Support Engineer
    ------------------------------


  • 2.  RE: UK Postcode regex
    Best Answer

    Posted yesterday

    Hello Tim, 

    The issues is that speech to text analytics transcripts 4 as four. Your regex pattern needs to accept both numeric digits and their word equivalents. 

    Option A - Simple for single digits

    ^[a-zA-Z]{1,2}d{1,2}s?(zero|one|two|three|four|five|six|seven|eight|nine|d)s?[a-zA-Z]{2}$

    Option B - More comprehensive UK post code regex with case insensitivity

    (?i)^[a-z]{1,2}[0-9]{1,2}s?([0-9]|zero|one|two|three|four|five|six|seven|eight|nine|ten)s?[a-z]{2}$

    Cheers, 



    ------------------------------
    Cameron
    Online Community Manager/Moderator
    ------------------------------



  • 3.  RE: UK Postcode regex

    Posted yesterday

    Thanks for the suggestion. Managed to get it working with:

    ^[a-zA-Z]{1,2}[0-9]{1,2}.?(?:[0-9]|zero|one|two|three|four|five|six|seven|eight|nine).[a-zA-Z]{2}$

    Very similar to yours but tweaked slightly.

    I still had to use some conversion afterwards to replace the 'four' to '4' and remove unnecessary spaces but at least it now passes validation.



    ------------------------------
    Tim Speakman
    Tech Support Engineer
    ------------------------------



  • 4.  RE: UK Postcode regex

    Posted yesterday

    I think this one works for mine

    \b[a-zA-Z]{1,2}\d[a-zA-Z\d]?\s*\d[a-zA-Z]{2}$ 



    ------------------------------
    Simon Brown
    Maintel Europe Limited
    Senior Applications Consultant
    ------------------------------