BP_XProfile_Field_Type::set_format( string $format, string $replace_format = 'add' )

Set a regex that profile data will be asserted against.

Description

You can call this method multiple times to set multiple formats. When validation is performed, it’s successful as long as the new value matches any one of the registered formats.

Parameters

$format

(string) (Required) Regex string.

$replace_format

(string) (Optional) if 'replace', replaces the format instead of adding to it. Defaults to 'add'.

Default value: 'add'

Return

(BP_XProfile_Field_Type)

Source

File: bp-xprofile/classes/class-bp-xprofile-field-type.php

	public function set_format( $format, $replace_format = 'add' ) {

		/**
		 * Filters the regex format for the field type.
		 *
		 * @since BuddyPress 2.0.0
		 *
		 * @param string                 $format         Regex string.
		 * @param string                 $replace_format Optional replace format If "replace", replaces the
		 *                                               format instead of adding to it. Defaults to "add".
		 * @param BP_XProfile_Field_Type $this           Current instance of the BP_XProfile_Field_Type class.
		 */
		$format = apply_filters( 'bp_xprofile_field_type_set_format', $format, $replace_format, $this );

		if ( 'add' === $replace_format ) {
			$this->validation_regex[] = $format;
		} elseif ( 'replace' === $replace_format ) {
			$this->validation_regex = array( $format );
		}

		return $this;
	}

Changelog

Changelog
Version Description
BuddyPress 2.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.