1. Home
  2. Docs
  3. WordPress Studio Framework
  4. How-To…
  5. Validate

Validate

Validate an email

array(
  'id' => 'example-email',
  'type' => 'text',
  'title' => 'Email Validation',
  'validate' => 'wpsf_validate_email',
),

//In some other location we would define the function
if ( ! function_exists( 'wpsf_validate_email' ) ){
  function wpsf_validate_email( $value ){
    if ( ! sanitize_email( $value ) ) {
      return esc_html__('Please write a valide email address!', 'wpsf');
    }
  }
}

Validate an email in the Customizer

array(
  'id' => 'example-email',
  'type' => 'text',
  'title' => 'Email Validation',
  'validate' => 'wpsf_validate_email',
),

//In some other location we would define the function
if ( ! function_exists( 'wpsf_validate_email' ) ){
  function wpsf_validate_email( $validity, $value, $wp_customize ){
    if ( ! sanitize_email( $value ) ) {
      $validity->add( 'required', esc_html__('Please write a valid email address!', 'wpsf' ) );
    }
    return $validity;
  }
}

Validate a numeric entry

array(
  'id' => 'example-number',
  'type' => 'text',
  'title' => 'Number Validation',
  'validate' => 'wpsf_validate_number',
),

//In some other location we would define the function
if ( ! function_exists( 'wpsf_validate_number' ) ){
  function wpsf_validate_number( $value ){
    if ( ! is_numeric( $value ) ) {
      return esc_html__('Please write a valid number!', 'wpsf');
    }
  }
}

Validate a url

array(
  'id' => 'example-url',
  'type' => 'text',
  'title' => 'URL Validation',
  'validate' => 'wpsf_validate_url',
),

//In some other location we would define the function
if ( ! function_exists( 'wpsf_validate_url' ) ){
  function wpsf_validate_url( $value ){
    if ( ! is_url( $value ) ) {
      return esc_html__('Please write a valid number!', 'wpsf');
    }
  }
}

 

Was this article helpful to you? Yes No

How can we help?