Reply To: Phone Number Validation

Home Forums User Registration Phone Number Validation Reply To: Phone Number Validation

#6870

sanjeev3
Member

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!