Regex for What3Words

Hi, wondering if anyone has managed to use regex to validate What3Words in a text field in Create?

I have been trying all morning without success!


Not tried it personally but there are a few examples online of possible solutions …

Our implementation of W3W actually does the lookup though so we don’t need to validate it in this way.

1 Like

Morning Henry,

Are you familiar with our what3words presenter on AppShare, or are you looking at a different use case.

var regex = /^\/{0,}(?:[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+|[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+){1,3})$/;

if (regex.test(text))
  print(text + " is the format of a three word address");
  print(text + " is NOT a three word address");

This is the recommendation as given by what3words.

A simpler interpretation would be /[a-z]+.[a-z]+.[a-z]+
This optionally allows for the 3
/// as well as three words separated by periods.

Thanks Adam, that simpler version has done the trick :grinning:

Thanks for your help, Haydn :+1: