XF 2.1 tag - replace to lowercase, whitespace with hyphen

-Eric-

Member
I would like to accept only a-z and 0-9 and hyphen.
Replace uppercase with lowercase, whitespace with hyphen, prevent accented letters.
typed "WINdows 10" replace to "windows-10"

in tag validation is this possible (and how)?
 

cwe

Active member
The Content Tagging option in the ACP does have a field for "Tag match regular expression:" which could be used to restrict the allowed characters. I'm not a Regex wizard though, so I can't really give you the proper expression to use.
 

frm

Well-known member
The below will give you the desired effect on an "Instagram" level where you may not begin a tag with a number, nor can you begin or end it with any special characters (hyphen included). IE: this-tag works but -this-tag- doesn't, 2019-doesnt, year-2019 does.
^(?!^\W)^(?!^\d)(?!.[I][\W]$)[a-z0-9-][/I]$

Facebook allows numbers in the beginning, and if you're looking at software, this might be best as some software might be named 1-virus-removal (example) which wouldn't work with the above as it excludes the first character being a digit. If you want that, and like 2019-windows-update to work, use below:
^(?!^\W)(?!.*[\W]$)[a-z0-9-]*$

Stick your preference in ACP -> Setup -> Options -> Content tagging -> "Tag match regular expression:"
 

frm

Well-known member
Oh, I get it. You want to convert WinDows-10 to windows-10.

That's not possible with the regex. It will only accept windows-10 and reject WinDows-10.

Probably need custom development.
 
Top