Klevr Product Documentation logo

Klevr Phone Number Validation PCF Control

The Klevr Phone Number Control is designed to ensure that phone numbers entered into forms are valid, standardized, and compliant with the E.164...

Feature Overview

The Klevr Phone Number Control is designed to ensure that phone numbers entered into forms are valid, standardized, and compliant with the E.164 international format. This control addresses the common problem of inconsistent phone number entry, which can lead to data quality issues, failed integrations, and user confusion. By enforcing E.164 formatting and allowing configuration of permitted country codes, the control ensures that only valid, expected phone numbers are accepted.

Benefits and Goals:

  • Enforces E.164 phone number format (e.g., +1234567890).
  • Allows configuration of allowed country codes (e.g., only accept numbers from specific countries).
  • Provides real-time validation feedback to users.
  • Prevents form submission if the phone number is invalid.
  • Supports default country code for local number entry.
  • Improves data quality and consistency for downstream systems.

Design Details

Input Field:

  • The control renders a single input field for phone number entry, with a placeholder guiding the user on the expected format.

Validation Logic:

  • Validates input against the E.164 format using a regular expression. Checks that the country code (the digits after the '+') matches one of the allowed country codes, if configured. Strips any leading '+' from allowed country codes for flexible configuration. Provides real-time feedback (valid, invalid, or partial) as the user types or pastes a number.

Error Messaging:

  • Displays clear error messages for invalid format or disallowed country codes. Shows which country codes are allowed if the input does not match.

Configuration:

  • Must be done on a text field. Note that you can change the existing Phone Number format to be text.
  • PCF Control name: klevr_control.PhoneNumberControl
  • allowedCountryCodes: Comma-separated list of allowed country codes (e.g., "1,44,64"). Accepts codes with or without a leading '+'.
  • defaultCountryCode: Used to auto-prefix numbers that do not start with '+'.

Integration:

  • Exposes isValid output property to prevent form submission when the number is invalid.

Last updated on