Maspik Documentation

Phone Field

The “Phone Field” options in the Maspik plugin allow you to protect phone number input fields from spam by enforcing specific formats, setting character limits, and displaying custom error messages. These options ensure that only correctly formatted phone numbers are accepted.

Phone Number Formats

Description:
This option allows you to set allowed phone number formats. If a phone number entered in the form does not match any of the specified formats, it will be marked as spam. Formats can be specified using wildcards or regular expressions.

How to Use:

  1. Open the plugin settings.
  2. Navigate to the Phone Fields accordion.
  3. Add each allowed phone number format on a separate line.

Examples of Phone Number Formats

Wildcard Formats for Phone Numbers

Here are some styles of wildcard formats that can be used:

  1. Regular characters: Match themselves exactly.
  2. *: Matches any sequence of characters (including zero characters).
  3. ?: Matches any single character.
  4. [...]: Matches any single character found within the square brackets.
  5. [!...] or [^...]: Matches any single character not found within the square brackets.
  6. {...,...}: Matches any of the comma-separated options.

Note: For a format to be recognized as a wildcard, it must contain either ‘*’ or ‘?’.

Examples of Wildcard Formats:

  1. +*-*-*: Matches a phone number that starts with ‘+’, followed by any number of digits, dash, digits, dash, digits.
  2. ???-???-????: Matches a phone number in the format of 3 digits, dash, 3 digits, dash, 4 digits.
  3. +[1-9]-*: Matches a phone number that starts with ‘+’, followed by a digit between 1 and 9, dash, and then any number of characters.
  4. {+*-*,???-???-????}: Matches one of two formats – either a number starting with ‘+’ or a number in the 3-3-4 format.
  5. [0-9][0-9][0-9]-*: Matches three digits, dash, and then any number of characters.

Regex Formats for Phone Numbers

For a format to be recognized as regex, it must start with a forward slash ‘/’.

Here are some simple examples of regex formats:

  1. /^\+\d{1,3}-\d{3}-\d{4}$/: Matches a phone number starting with ‘+’, followed by 1 to 3 digits, then ‘-‘, 3 digits, ‘-‘, and 4 digits.
  2. /^(\d{3}[-\.\s]??\d{3}[-\.\s]??\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]??\d{4}|\d{3}[-\.\s]??\d{4})$/: Matches various common US phone number formats.
  3. /^\+?[\d\s]{3,}$/: Matches a phone number that optionally starts with ‘+’, followed by at least 3 digits or spaces.
  4. /^[0-9]{10}$/: Matches exactly 10 digits.
  5. /^\(\d{3}\)\s?\d{3}-\d{4}$/: Matches a phone number in the format (123) 456-7890 or (123)456-7890.

Here you can see the formats from the above examples clearly:

+*-*-*
???-???-????
+[1-9]-*
{+*-*,???-???-????}
[0-9][0-9][0-9]-*
/^\+\d{1,3}-\d{3}-\d{4}$/
/^(\d{3}[-\.\s]??\d{3}[-\.\s]??\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]??\d{4}|\d{3}[-\.\s]??\d{4})$/
/^\+?[\d\s]{3,}$/
/^[0-9]{10}$/
/^\(\d{3}\)\s?\d{3}-\d{4}$/

Risk:
Setting too restrictive formats may block legitimate phone numbers. Ensure to include all common formats used by your target audience. Regularly review the spam log to ensure no valid phone numbers are being mistakenly blocked.

Custom Error Message for Phone Number Formats

Description:
This option allows you to set a custom error message that will be displayed when the user enters a phone number that does not match any of the allowed formats.

How to Use:

  1. Open the plugin settings.
  2. Navigate to the Phone Fields section.
  3. Turn on the Custom error message toggle.
  4. Enter your custom error message.

Example:

Enter a message like:

Please enter a valid phone number.

to inform the user exactly what the issue is and how to fix it.

Limit digits in phone numbers

Description:
This option allows you to set minimum and maximum digit limits for the phone number field. Numbers that are too short or too long will be marked as spam.

How to Use:

  1. Open the plugin settings.
  2. Navigate to the Phone Fields accordion, and turn on the Limit characters toggle.
  3. Enter the minimum and maximum number of allowed characters.

Example:

  • If you set the minimum value to 8 and the maximum value to 13, any phone number with fewer than 8 characters or more than 13 characters will be marked as spam.

Risk:
Setting the character limits too restrictively may block legitimate phone numbers. Ensure to set reasonable limits and periodically check the spam log for false positives. For example, setting a minimum of 7 characters and a maximum of 15 characters can usually balance spam prevention and legitimate user submissions.

Custom Error Message for Character Limit

Description:
This option allows you to set a custom error message that will be displayed when the user exceeds the minimum or maximum number of characters in the phone number field.

How to Use:

  1. Open the plugin settings.
  2. Navigate to the Phone Fields section, and turn on the Custom error message toggle.
  3. Enter your custom error message.

Example:

Enter a message like

Your phone number must be between 7 and 15 characters long.

to inform the user exactly what the issue is and how to fix it.