How do I create a Custom Mask?

Modified on Thu, 13 Feb at 1:46 PM

Custom Mask Expressions in Droplet let you define exactly how a user’s input should be structured in an Input (Single Line) component.  By restricting allowable characters and formatting patterns, you can ensure cleaner, more consistent data in your forms.

When Should I Use a Custom Mask?

Masks in Droplet help ensure consistent, valid data entry. For instance, if you want a user to enter a specific number of digits (like a phone number) or strictly allow letters only (like a middle initial), custom masks let you define rules that enforce the exact format and type of characters entered.


Typically, you’d use a custom mask when:

You want to limit or validate input character-by-character in a single-line text field.
None of the Built-in Masks (like phone number, SSN, ZIP code) fit your use-case.

In essence, a custom mask is your go-to tool when you want to control exactly how input gets typed.

/9
Numeric character placeholder (0-9) 
Example Use
/9/9/9/9
Accepts exactly 4 digits (like a year).
/a
Alphabetic character placeholder (A-Z, a-z)
Example Use
/a 
Accepts exactly 1 letter (like a middle initial).
/*
Alpha-numeric placeholder (letters or digits)
Example Use
/* 
Accepts exactly 15 alpha-numeric characters (e.g., Batch ID).
/l
Lowercase character placeholder
Example Use
 /l/l 
Accepts exactly 2 lowercase letters.
/u
Uppercase character placeholder
Example Use
 /u/u/u 
Accepts exactly 3 uppercase letters.
/?
Any character placeholder (a wildcard)
Example Use
 /?/?-/?/?/? 
Accepts exactly 2 characters, then a dash, then exactly 3 characters.  No restriction on letters, digits, etc.
Literal Characters
Certain characters appear exactly as typed — they are not placeholders. These can be letters, numbers, punctuation, parentheses, dashes, dots, etc.

Examples:
 3, G, -, (, ), ., :, /
Example Use
ABC-/9/9/9
This mask accepts 3 numeric digits, but must begin with ABC- first (e.g. ABC-123 or ABC-456).
User-Defined Sets
Lets you specify exactly which characters are allowed. Use square brackets to define your set.
Example Use
/[a-d123] 
Accepts only letters a, b, c, d and digits 1, 2, 3 in a single slot.
Ranges
Specify exact or variable lengths using parentheses. You can do exact or min:max.
Example Uses
/(3)9 
Exactly three digits.

/(2:3)9 
Accepts between 2 and 3 digits. Perfect for optional digit lengths (e.g., 99 or 999).
NOT Operator (!)
Exclude certain characters or sets with !
2 Exceptions
Cannot use the NOT operator with ranges or with the wildcard (for example, /!? is invalid).
Example Use
 /!9/!9/!9 
Three characters, each must not be a digit. Could be letters, punctuation, etc. (e.g., XYZ, !!!, but not 123).



Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article