> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oneclickdz.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Validate Phone Number

> Validate phone numbers before processing internet top-up

## Overview

Validates phone numbers for ADSL or 4G services before submission. Helps prevent errors and reduces refund issues.

<Tip>
  **Always validate** phone numbers before submitting top-up requests to
  minimize failures.
</Tip>

## Query Parameters

<ParamField query="type" type="string" required>
  Service type: `ADSL` or `4G`
</ParamField>

<ParamField query="number" type="string" required>
  Phone number to validate - **ADSL:** `0[0-9]{8}` (e.g., `036362608`) - **4G:**
  `213[0-9]{9}` (e.g., `213472731602`)
</ParamField>

## Response

### Valid ADSL Number

```json theme={null}
{
  "success": true,
  "data": {
    "ncli": "11022*****",
    "offre": "FTTc-b_10M'",
    "type": "ADSL"
  },
  "meta": {
    "timestamp": "2025-10-29T00:36:48.823Z"
  }
}
```

### Valid 4G Number

```json theme={null}
{
  "success": true,
  "data": {
    "ncli": "11034*****",
    "type": "4GLTE"
  },
  "meta": {
    "timestamp": "2025-10-29T00:36:49.847Z"
  }
}
```

### Invalid Number

```json theme={null}
{
  "success": false,
  "error": {
    "code": "ERR_PHONE",
    "message": "Invalid phone number for ADSL service",
    "details": {
      "number": "123456",
      "type": "ADSL",
      "reason": "Number does not match required format"
    }
  }
}
```

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://api.oneclickdz.com/v3/internet/check-number?type=ADSL&number=036362608" \
    -H "X-Access-Token: YOUR_API_KEY"
  ```

  ```javascript Node.js theme={null}
  async function validateNumber(type, number) {
    const response = await fetch(
      `https://api.oneclickdz.com/v3/internet/check-number?type=${type}&number=${number}`,
      { headers: { "X-Access-Token": process.env.API_KEY } }
    );

    if (!response.ok) {
      const error = await response.json();
      throw new Error(error.error.message);
    }

    return await response.json();
  }

  // Usage
  try {
    await validateNumber("ADSL", "036362608");
    console.log("Number is valid");
  } catch (error) {
    console.error("Invalid number:", error.message);
  }
  ```

  ```python Python theme={null}
  def validate_number(type, number):
      response = requests.get(
          'https://api.oneclickdz.com/v3/internet/check-number',
          headers={'X-Access-Token': 'YOUR_API_KEY'},
          params={'type': type, 'number': number}
      )

      if response.ok:
          return True
      else:
          error = response.json()
          raise ValueError(error['error']['message'])

  # Usage
  try:
      validate_number('ADSL', '036362608')
      print('Valid number')
  except ValueError as e:
      print(f'Invalid: {e}')
  ```

  ```php PHP theme={null}
  <?php
  function validateNumber($type, $number) {
      $url = "https://api.oneclickdz.com/v3/internet/check-number?type={$type}&number={$number}";
      $ch = curl_init($url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Access-Token: YOUR_API_KEY']);
      $response = curl_exec($ch);
      $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);

      if ($httpCode === 200) {
          return true;
      } else {
          $error = json_decode($response, true);
          throw new Exception($error['error']['message']);
      }
  }

  // Usage
  try {
      validateNumber('ADSL', '036362608');
      echo "Valid number\n";
  } catch (Exception $e) {
      echo "Invalid: " . $e->getMessage() . "\n";
  }
  ?>
  ```
</CodeGroup>

## Phone Number Formats

<Tabs>
  <Tab title="ADSL">
    **Format:** `0[0-9]{8}` **Valid Examples:** - ✅ `036362608` - ✅
    `031417237` - ✅ `021123456` **Invalid Examples:** - ❌ `36362608` (missing
    leading 0) - ❌ `0363626081` (too long) - ❌ `213636362608` (wrong format)
  </Tab>

  <Tab title="4G">
    **Format:** `213[0-9]{9}` **Valid Examples:** - ✅ `213472731602` - ✅
    `213665983439` - ✅ `213778037340` **Invalid Examples:** - ❌ `0665983439`
    (wrong format, should include country code) - ❌ `665983439` (missing
    country code) - ❌ `+213665983439` (shouldn't include +)
  </Tab>
</Tabs>

## Integration Example

```javascript theme={null}
// Complete validation flow
async function prepareInternetTopup(type, number, value) {
  // Step 1: Validate number
  try {
    await validateNumber(type, number);
  } catch (error) {
    return {
      success: false,
      error: "Invalid phone number",
      details: error.message,
    };
  }

  // Step 2: Check product availability
  const products = await getProducts(type);
  const product = products.find((p) => p.value === value && p.available);

  if (!product) {
    return {
      success: false,
      error: "Product not available",
    };
  }

  // Step 3: Send top-up
  return await sendInternetTopup({ type, number, value });
}
```

## Why Validate?

<CardGroup cols={2}>
  <Card title="Reduce Errors" icon="shield-check">
    Catch invalid numbers before submission
  </Card>

  <Card title="Better UX" icon="smile">
    Show immediate feedback to users
  </Card>

  <Card title="Fewer Refunds" icon="money-bill-wave">
    Minimize failed transactions and refunds
  </Card>

  <Card title="Verify Format" icon="list-check">
    Ensure number matches service type
  </Card>
</CardGroup>

## Best Practices

<AccordionGroup>
  <Accordion title="Client-Side Validation">
    Validate format client-side first, then confirm with API:

    ```javascript theme={null}
    function validateADSLFormat(number) {
      return /^0[0-9]{8}$/.test(number);
    }

    function validate4GFormat(number) {
      return /^213[0-9]{9}$/.test(number);
    }
    ```
  </Accordion>

  {" "}

  <Accordion title="Show Helpful Messages">
    Display clear messages when validation fails: - "Please enter a valid ADSL
    number (e.g., 036362608)" - "4G numbers should start with 213 (e.g.,
    213665983439\)" - "Number format: 9 digits starting with 0"
  </Accordion>

  <Accordion title="Cache Validation Results">
    Cache successful validations for a short period:

    ```javascript theme={null}
    const validationCache = new Map();

    async function validateWithCache(type, number) {
      const key = `${type}:${number}`;
      
      if (validationCache.has(key)) {
        return validationCache.get(key);
      }
      
      const result = await validateNumber(type, number);
      validationCache.set(key, result);
      
      // Clear after 5 minutes
      setTimeout(() => validationCache.delete(key), 5 * 60 * 1000);
      
      return result;
    }
    ```
  </Accordion>
</AccordionGroup>

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Products" icon="list" href="/en/api-reference/internet/list-products">
    Get available cards
  </Card>

  <Card title="Send Top-Up" icon="paper-plane" href="/en/api-reference/internet/send-topup">
    Purchase internet card
  </Card>
</CardGroup>
