How to Validate a Phone Field in Shack Forms

In some cases, you may need to ensure that a Shack Forms user can enter only a phone number in a certain field.

  • Open your Shack Forms module for editing.
  • Open the field that needs to be limited only to numeric data.
  • Set the Field type to Text.
  • Enter /^[\d\-\+() ]+$/into the Validation (Regular Expression) field:

the validation code for a number field

  • Click Save or Save & Close.

If you go to your form and enter a letter into this field, both the field label and the field itself get displayed in red color, indicating an input error:

alpha characters flagged as error