# Phone Number Field on Registration and Profiles

> Adds a phone number field to the WordPress registration form, saves it with the new account and lets users and admins edit it on the profile screen.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: registration, users, phone
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/form-registration-phone-field/

## Code

```php
$wpide_phone_required = true;

add_action( 'register_form', function () use ( $wpide_phone_required ) {
    $value = isset( $_POST['wpide_phone'] ) ? sanitize_text_field( wp_unslash( $_POST['wpide_phone'] ) ) : '';
    printf( '<p><label for="wpide_phone">Phone number</label><input type="tel" name="wpide_phone" id="wpide_phone" class="input" value="%s" autocomplete="tel"%s></p>', esc_attr( $value ), $wpide_phone_required ? ' required' : '' );
} );

add_filter( 'registration_errors', function ( $errors ) use ( $wpide_phone_required ) {
    $phone  = isset( $_POST['wpide_phone'] ) ? (string) wp_unslash( $_POST['wpide_phone'] ) : '';
    $digits = strlen( preg_replace( '/\D/', '', $phone ) );

    if ( ( $wpide_phone_required || '' !== $phone ) && ( $digits < 7 || $digits > 15 || ! preg_match( '/^\+?[0-9\s().\-]+$/', $phone ) ) ) {
        $errors->add( 'wpide_phone', '<strong>Error:</strong> Please enter a valid phone number.' );
    }

    return $errors;
} );

add_action( 'user_register', function ( $user_id ) {
    if ( isset( $_POST['wpide_phone'] ) ) {
        update_user_meta( $user_id, 'phone', sanitize_text_field( wp_unslash( $_POST['wpide_phone'] ) ) );
    }
} );

add_filter( 'user_contactmethods', function ( $methods ) {
    $methods['phone'] = 'Phone number';

    return $methods;
} );
```

## Notes

Set $wpide_phone_required to false to make it optional; the number is stored in user meta named phone.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Phone Number Field on Registration and Profiles" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
