Score:0

Use first 3 digits of views contextual filter as filter criteria

nr flag

I have a view that fetches a Belgian postal code, which always has 4 digits, from the URL and uses it as contextual filter to only show nodes for that postal code. This works fine.

I would like to also show sub-localities in this view. Given a postal code equal to 9990, the view should show the node for 9990 but also the nodes for 9991 and 9992, and other nodes whose postal code's first three digits are 999.

Is it possible to use the regex operator in the view filter for this, for example REGEXP_EXTRACT(%,"^.{0,3}") which doesn't actually work?

Preferably I'd like to solve this in the view itself and not with code.

Score:0
cn flag

Views Custom Regex

Module VCR has a String filter according to the code which maybe help using Start with.

Views Contextual Filter Validator: Regular Expression (regex)

Maybe usefull to validate the input?

You cannot use Views Contextual Filter Validator: Regular Expression (regex) as it is a validator only as explained in Can the regex extract portion of filter value for use?

Views Contextual Filter Validator: Regular Expression adds a Views contextual filter validator that can evaluate an argument based on user-supplied regular expression pattern.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.