Forum

Thread tagged as: Question, Forms, Field-Types

Prevent inputting of commas

Is it possible to prevent a content editor from inputting a comma into a text field? Like with

pattern="[a-zA-Z.-]"

on a regular text field.
I have the editors feed the options for a select field of a Perch Form through the backend.
Chances are high, they will input a comma, which will split the options in the wrong place.

Nils Mielke

Nils Mielke 3 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Could you replace the comma if it exists using the replace attribute?

Sounds good.
Unfortunately it doesn't seem to work. Here's my code:

<perch:content id="name" type="text" replace=",|;" label="Name" />

When I enter "Mielke, N." into the text input in the Perch backend, the comma is interpreted as a divider and the Strings "Mielke" and "N." become separate options of the select field.

When I replace something else than the comma, e.g.

<perch:content id="email" type="text" label="E-Mail-Adresse" replace="@|[at]" />

it works perfectly.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah, the replace attribute is comma delimited too. So that's no good.

Escaping the comma with a backslash doesn't seem to do the trick either.
Any other ideas?

(Love the possibilities of replace, though. Thanks for that hint.)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Another suggestion would be to add some JavaScript as a UI plugin and check the field that way.

I'll look into that.
Thanks, Drew.