Phone Number Validation

Home Forums User Registration Phone Number Validation

This topic contains 13 replies, has 3 voices, and was last updated by  artisanfx 1 week ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #6762

    Michael
    Participant

    Hi,

    is it possible to validate phone numbers? I’m using the Woocommerce integration addon and the Woocommerce “Phone” field has no input mask option. Would it work to user the advance field “Phone” and set “Field Name” to “billing_phone”
    In general, how can I adjust form field validations for fields (“input mask”)?

    Best,
    Michael

    #6829

    sanjeev3
    Moderator

    Hello,

    Currently, input mask is only available for phone field. Input masks on the billing and shipping phone fields are missing. We will introduce input masks to these fields soon.

    Adding billing_phone in the field name only doesnot work because the ‘user_registration_’ prefix will be added to all custom fields.

    However, you can add the billing_phone to the field name of phone field and donot add prefix with the following code.

    add_action( 'user_registration_fields_without_prefix', 'ur_add_no_prefix' );
    function ur_add_no_prefix( $fields ) {
    
    	$fields[] = 'phone';
    
    	return $fields;
    } 

    Let me know if you have any further confusion.

    Regards,
    WPEverest Support

    #6845

    Michael
    Participant

    Many thanks, but I just realized that input mask is not validation pattern like: ^\+?\d{0,13}. I would need a pattern, because there is a range of different phone number lengths. Is there any possibility to add html validation patterns?

    Furthermore, I would like to add woocommerce billing_title which should be a select with options like Mr. and Mrs. Because it is not available under woocommerce fields, I tried to use an extra select field and removing the prefix but it didn’t work with the following code:

    add_action( 'user_registration_fields_without_prefix', 'ur_add_no_prefix' );
    function ur_add_no_prefix( $fields ) {
    
        $fields[] = 'select';
    
        return $fields;
    }

    Maybe you could also add a woocommerce title field (‘billing_title’)?

    Best,
    Michael

    #6870

    sanjeev3
    Moderator

    Hello Michael,

    Yes. You can apply regex validation from backend. Client side regex validation is not available. This means the validation error message appears only after form submit. Here is the code:

    add_action( 'user_registration_validate_billing_phone','ur_validate_billing_phone',10,4);
    function ur_validate_billing_phone( $single_form_field, $data, $filter_hook, $form_id) {
    	$field_label = isset( $data->label ) ? $data->label : '';
    	$value = isset( $data->value ) ? $data->value : '';
    
    	if( 1 === preg_match( '^\+?\d{0,13}^', $value ) ) {
    	    add_filter( $filter_hook, function ( $msg ) use ( $field_label ) {
    	        return __( $field_label . ' is an invalid phone number.', 'user-registration' );
    	   });
    	}
    }

    billing_adddress_title is availalbe as an input field. The first Billing Address field under WooCommerce Billing Fields is a billing address title field. Select field is not available for title field.

    Thank You!

    #6994

    artisanfx
    Participant

    hi
    sorry first for my bad english but i try to explain as good as i can

    i have just install your plugin and it runs nicely and smooth on my site
    i have a question about the phone input section
    when new user register with name, address and telefon etc

    it adds all the information in the profile in a differend parts
    is there a way to add the phone number to a option in the user profile thats already was created before to it ?
    like to the data billing_phone = meta_key ?

    thank you

    #6996

    artisanfx
    Participant

    i see in the data base that the plugin use meta data -user_registration_number_box_1543450026

    how can i add the phone to billing_phone data indeed not to user_registration_number_box_1543450026

    #7005

    sanjeev3
    Moderator

    Hello artisanfx,

    If you already have the User registration WooCommerce add-on, you can get Billing Phone field with meta key billing_phone by default, you don’t need to tweak anything. If not, you can still follow above instructions. Drag the number field. change the it’s field key from number_box_1543450026 to billing_phone. And, with the code provided above, no prefix will be added and the meta key will only be billing_phone.

    Let me know if you mean something else.

    Regards,
    WPEverest Support

    #7010

    artisanfx
    Participant

    yes i have seen the code above but sorry i am realy new in php
    may i ask you where do i need to add the code
    if you can point me in the right direction would be really great 🙂

    thanks

    #7112

    artisanfx
    Participant

    where do i need to set the code ? please help

    #7168

    sanjeev3
    Moderator

    Hey, you need to paste the codes in your child theme’s functions.php. Here is the tutorial for that: https://themegrill.com/blog/tutorial-creating-wordpress-child-theme/ If you are unfamiliar with these stuffs, please donot add anything, any errors may result your site to crash. This is more of the developers guide.

    Automatic option for this feature is not available.

    Regards,
    WPEverest Support

    #7172

    artisanfx
    Participant

    thank you I will try this

    and thanks also for the warning but i add this on a test site first and will see if this works
    Warm Regards

    #7358

    artisanfx
    Participant

    i follow all the steps but this is not working for me 🙁

    #7396

    sanjeev3
    Moderator

    Hello again,

    Can you please be more clear what you are trying to acheive. If you are trying to add billing_phone with custom number field? Add meta key billing_phone to the field name option, instead of number_1233432345 and the following codes to your child theme’s functions.php

    add_action( 'user_registration_fields_without_prefix', 'ur_add_no_prefix' );
    function ur_add_no_prefix( $fields ) {
    
        $fields[] = 'number';
    
        return $fields;
    }

    Hope this helps!

    Regards,
    WPEverest Support

    #7405

    artisanfx
    Participant

    yes i did this but it is not working for me maybe because i am using multiply themes on multiply domain
    anyway thanks for tying to help i think i need to make this manual copy and past it over in the profile of each user who will be new register on the page

    Thanks
    Regards
    artisanfx

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.