Usage

HTML (Auto-init)

HTML
<input type="text" class="fw-phone" id="phone">

<script>
  FormWidgets.autoInit();
</script>

HTML with Data Attributes

HTML
<input type="text" class="fw-phone"
       data-pattern="+44 ## #### ####"
       data-show-pattern="true">

JavaScript Initialization

JavaScript
FormWidgets.init('#phone', 'PhoneField', {
    pattern: '+44 ## #### ####',
    showPattern: true
});

Options

OptionTypeDefaultDescription
patternstring'(###) ###-####'Phone pattern where # represents a digit. Fixed characters (spaces, parentheses, dashes) are inserted automatically.
allowPartialbooleantrueWhen true, allows incomplete numbers without showing a validation error. Set to false for strict validation.
showPatternbooleantrueWhen true, shows the pattern as a placeholder with _ replacing # (e.g. +44 __ ____ ____).
iconstring'phone'Name of the SVG icon to use from the internal icon set.
requiredbooleanfalseMarks the field as required.

Data Attributes

Data AttributeEquivalent OptionExample
data-patternpatterndata-pattern="+44 ## #### ####"
data-allow-partialallowPartialdata-allow-partial="false"
data-show-patternshowPatterndata-show-pattern="true"
data-requiredrequireddata-required="true"

Pattern Syntax

The pattern option uses # as a placeholder for each digit. All other characters are treated as fixed formatting and inserted automatically.

PatternPlaceholderExample OutputUse Case
(###) ###-####(___) ___-____(555) 123-4567US standard
+44 ## #### ####+44 __ ____ ____+44 20 7946 0958UK landline with +44
+44 ##### ######+44 _____ ______+44 07700 900123UK mobile with +44
##### ######_____ ______07700 900123UK mobile local
### #### ####___ ____ ____020 7946 0958UK landline local
+## (###) ###-####+__ (___) ___-____+1 (555) 123-4567International

UK Number Handling

Auto-remove Leading Zero for +44

When the pattern starts with +44 and the user types 11 digits starting with 0 (e.g. 07700900123), the leading 0 is automatically removed to produce the correct international format: +44 7700 900123.

Features

Auto-formatting

Digits and separators are inserted automatically as you type.

Pattern Placeholder

The pattern is shown with underscores as a placeholder guide.

UK Support

Auto-removes leading 0 when switching to +44 international format.

Any Format

Define any phone pattern — US, UK, international, or custom.