Drupal Forms User Guide
Patterns
Making sure that users enter answers in a set pattern reduces the risk of errors. For example, email addresses and National Insurance numbers.
Validation can be added to fields so they won't accept the wrong pattern.
Use custom elements
Some elements have pattern validation built in. Use them instead of a text field so you don't have to add it manually.
For example, email fields will not accept input without "@" with characters either side of it and "." followed by more characters.
Input masks
An input mask specifies a pattern of numbers, letters or both for a text field.
You can add them under form display in the field's general settings.
There are a range of presets, but most are US formats.
Select custom to specify your own. Here are some examples.
Regular expressions
A regular expression (regex) can be added to add more complex patterns validation to a field.
They are added by toggling on pattern under form validation in the field's general settings
There are some examples on Drupal.org.