Contact form 7 telephone number verification

Contact form 7 telephone number verification

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Contact Form 7 Telephone Number Verification

Contact Form 7 offers a built-in verification method for numeric inputs, which works well for simple fields like age or quantity. However, applying this same logic to telephone numbers often leads to unexpected behavior because the underlying validation mechanism treats input as a plain integer. When you define a field using [number* your-telephone min:1000000000 max:9999999999], the plugin attempts to parse the string as an unsigned 32-bit integer. This creates a fundamental conflict with real-world telephony formats.

The core issue arises from the range limit of standard JavaScript numbers and the specific parsing rules Contact Form 7 applies. The maximum safe integer in JavaScript is $2^{53} - 1$ (approximately 9,007,199,254,740,991), but Contact Form 7's internal validation for the number type often defaults to checking against a much smaller range, typically capping out at 999,999,999 (nine digits) or failing entirely on values exceeding the 32-bit integer limit depending on the browser environment. Consequently, entering a valid 10-digit number like 0402356584 (or a larger one like 9999999999) triggers a validation error because the input is interpreted as exceeding the maximum allowed value for that specific input type configuration.

To restrict phone numbers effectively, you must abandon the [number] field type in favor of [text]. The [number] type adds a hidden HTML5 <input type="number"> attribute which enforces numeric-only keystrokes on mobile devices but strictly enforces integer ranges that do not align with international dialing codes. Switching to [text] removes these artificial range constraints while still allowing you to enforce length requirements through the minlength and maxlength attributes, or by leveraging a custom validation script.

Here is how you can implement a robust solution without modifying core plugin files:

<p>
    [text* your-telephone placeholder "Telephone number" minlength="10" maxlength="15"]
</p>
<p>
    [submit "submit"]
</p>

By switching the field type to text, you remove the hard ceiling imposed by the plugin's integer parser. You can then use the minlength and maxlength attributes to constrain the character count. For example, setting minlength="10" ensures that users cannot submit numbers shorter than 10 digits, which covers most national formats including those with leading zeros (e.g., 0402356584). Setting maxlength="15" accommodates international numbers with country codes while preventing excessively long entries.

If you require more sophisticated validation—such as validating the format of a specific country's dialing code or allowing leading zeros within the integer range—you should implement custom JavaScript validation in your theme's functions.php file using a shortcode hook. Contact Form 7 supports custom validation scripts via the [submit] tag attributes or by adding a <script> block to your form. This approach allows you to write logic that specifically checks for patterns rather than relying on generic min/max integer comparisons.

For instance, if you are building a Laravel application and need to handle this data on the backend as well, ensure your server-side validation mirrors the client-side constraints. While Contact Form 7 handles the initial client check, the @rules('required|min:10|max:15') syntax in Laravel can provide an additional layer of security against malformed submissions that bypass client-side checks.

Avoid trying to force the built-in min and max properties of the [number] type to accommodate phone numbers; the architecture of that input type simply does not support leading zeros or values above 999,999,999 correctly in all contexts. The most reliable path is to treat the telephone number as a string and validate its length and format accordingly.

Our network