We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

Phone Input Component

The Phone Input component provides a modern, user-friendly interface for collecting phone numbers. It features automatic formatting, area code selection, and validation to ensure proper phone number entry.

  • Check Circle

    Automatic Formatting: Real-time formatting as users type

  • Check Circle

    Area Code Selection: Built-in country code selection

  • Check Circle

    Input Validation: Real-time validation with error messages

  • Check Circle

    Paste and Autofill: Gracefully handles pasting and browser autofill

  • Check Circle

    Form Integration: Seamless integration with form data

Create a simple phone input field:

Phone Number
<PhoneInput
label="Phone Number"
name="phone"
/>
Small
Medium
Large
Contact Number *
Phone Number
We'll use this to send you important updates

The phone input component provides several functions to interact with programmatically:

Function Type Description
get: value () => string Gets the complete phone number with area code
set: value (value: string) => void Sets the phone number value
get: areaCode () => string Gets the currently selected area code
set: areaCode (code: string) => void Sets the area code
set: required (required: boolean) => void Sets whether the input is required
Phone Input Component Props Extends ComponentProps<typeof Input>
Prop Type Description
label string Label text for the input
sublabel string Additional text below the input
wrapperProps HTMLAttributesWithData<"div"> Props for the wrapper div
areaCodeProps ComponentProps<typeof Select> Props for the area code select

The phone input component automatically validates the entered phone number and displays error messages when:

  • The number format is invalid (must match XXX-XXX-XXXX pattern)
  • Required field is empty
  • Area code is missing when required
Phone Number (with validation) *

The phone input component handles various phone number formats:

  • Automatically formats as user types: XXX-XXX-XXXX
  • Stores complete number with area code: +1234567890
  • Strips non-numeric characters for processing
  • Supports international format with ’+’ prefix
// Setting a phone number value
phoneInput.value = '+12345678900';
// Getting the formatted value
const number = phoneInput.value; // Returns: "+12345678900"
// The displayed value will be formatted as: 234-567-8900

Limited Time Launch Sale

Add professional phone number input to your forms with our Phone Input component.

GET 60% OFF!
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes