Skip to main content

Phone Verification Tool

SMS-based phone number verification with global coverage and advanced fraud detection.

🎯 What is Phone Verification?​

Phone verification uses SMS to verify phone numbers, ensuring users have access to the phone number they provide. It's essential for account security, two-factor authentication, and preventing fake accounts.

βš™οΈ Setup & Configuration​

Basic Implementation​

const verifyPhone = async (phoneNumber) => {
try {
const response = await fetch('https://api.trustedaccounts.org/phone/YOUR_PUBLISHABLE_KEY/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
phone: phoneNumber,
country: 'US' // Optional country code
})
});

const result = await response.json();
return result;
} catch (error) {
console.error('Phone verification failed:', error);
return { success: false, error: 'Verification service unavailable' };
}
};

// Usage
verifyPhone('+1234567890').then(result => {
if (result.success) {
console.log('SMS sent! Verification code:', result.code);
} else {
console.log('Phone verification failed:', result.error);
}
});

Advanced Configuration​

const verifyPhoneAdvanced = async (phoneNumber, options = {}) => {
const defaultOptions = {
country: 'US',
language: 'en',
timeout: 300, // 5 minutes
retries: 3, // Max retry attempts
template: 'default' // SMS template
};

const verificationOptions = { ...defaultOptions, ...options };

try {
const response = await fetch('https://api.trustedaccounts.org/phone/YOUR_PUBLISHABLE_KEY/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
phone: phoneNumber,
...verificationOptions
})
});

return await response.json();
} catch (error) {
console.error('Phone verification failed:', error);
return { success: false, error: 'Verification service unavailable' };
}
};

πŸ“± Verification Flow​

Step 1: Send Verification Code​

// Send verification code
const sendCode = async (phoneNumber) => {
const result = await verifyPhone(phoneNumber);

if (result.success) {
// Store verification ID for later use
localStorage.setItem('verificationId', result.verificationId);
console.log('Verification code sent to', phoneNumber);
} else {
console.error('Failed to send code:', result.error);
}
};

Step 2: Verify Code​

const verifyCode = async (code) => {
const verificationId = localStorage.getItem('verificationId');

try {
const response = await fetch('https://api.trustedaccounts.org/phone/YOUR_PUBLISHABLE_KEY/verify-code', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
verificationId: verificationId,
code: code
})
});

const result = await response.json();
return result;
} catch (error) {
console.error('Code verification failed:', error);
return { success: false, error: 'Verification service unavailable' };
}
};

// Usage
verifyCode('123456').then(result => {
if (result.success) {
console.log('Phone verified successfully!');
localStorage.removeItem('verificationId');
} else {
console.log('Invalid verification code');
}
});

πŸ”§ Server-Side Integration​

Node.js/Express Example​

app.post('/api/verify-phone', async (req, res) => {
const { phone } = req.body;

try {
const response = await fetch('https://api.trustedaccounts.org/phone/YOUR_PUBLISHABLE_KEY/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
phone: phone,
country: 'US'
})
});

const result = await response.json();

if (result.success) {
res.json({
success: true,
message: 'Verification code sent',
verificationId: result.verificationId
});
} else {
res.status(400).json({
success: false,
error: result.error
});
}
} catch (error) {
console.error('Phone verification error:', error);
res.status(500).json({ error: 'Verification service unavailable' });
}
});

app.post('/api/verify-code', async (req, res) => {
const { verificationId, code } = req.body;

try {
const response = await fetch('https://api.trustedaccounts.org/phone/YOUR_PUBLISHABLE_KEY/verify-code', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
verificationId: verificationId,
code: code
})
});

const result = await response.json();

if (result.success) {
res.json({
success: true,
message: 'Phone verified successfully',
phone: result.phone
});
} else {
res.status(400).json({
success: false,
error: result.error
});
}
} catch (error) {
console.error('Code verification error:', error);
res.status(500).json({ error: 'Verification service unavailable' });
}
});

Python/Django Example​

import requests
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import json

@csrf_exempt
def verify_phone(request):
if request.method == 'POST':
data = json.loads(request.body)
phone = data.get('phone')

# Send verification code
verify_url = 'https://api.trustedaccounts.org/phone/YOUR_PUBLISHABLE_KEY/verify'
verify_data = {
'phone': phone,
'country': 'US'
}

try:
response = requests.post(verify_url, json=verify_data)
result = response.json()

if result.get('success'):
return JsonResponse({
'success': True,
'message': 'Verification code sent',
'verificationId': result.get('verificationId')
})
else:
return JsonResponse({
'success': False,
'error': result.get('error')
}, status=400)

except requests.RequestException as e:
return JsonResponse({
'error': 'Verification service unavailable'
}, status=500)

return JsonResponse({'error': 'Invalid request'}, status=400)

@csrf_exempt
def verify_code(request):
if request.method == 'POST':
data = json.loads(request.body)
verification_id = data.get('verificationId')
code = data.get('code')

# Verify code
verify_url = 'https://api.trustedaccounts.org/phone/YOUR_PUBLISHABLE_KEY/verify-code'
verify_data = {
'verificationId': verification_id,
'code': code
}

try:
response = requests.post(verify_url, json=verify_data)
result = response.json()

if result.get('success'):
return JsonResponse({
'success': True,
'message': 'Phone verified successfully',
'phone': result.get('phone')
})
else:
return JsonResponse({
'success': False,
'error': result.get('error')
}, status=400)

except requests.RequestException as e:
return JsonResponse({
'error': 'Verification service unavailable'
}, status=500)

return JsonResponse({'error': 'Invalid request'}, status=400)

PHP Example​

<?php
// Send verification code
if ($_POST && isset($_POST['phone'])) {
$phone = $_POST['phone'];

$verify_url = 'https://api.trustedaccounts.org/phone/YOUR_PUBLISHABLE_KEY/verify';
$verify_data = json_encode([
'phone' => $phone,
'country' => 'US'
]);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $verify_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $verify_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($http_code === 200) {
$result = json_decode($response, true);

if ($result['success']) {
echo json_encode([
'success' => true,
'message' => 'Verification code sent',
'verificationId' => $result['verificationId']
]);
} else {
http_response_code(400);
echo json_encode([
'success' => false,
'error' => $result['error']
]);
}
} else {
http_response_code(500);
echo json_encode(['error' => 'Verification service unavailable']);
}
}

// Verify code
if ($_POST && isset($_POST['verificationId']) && isset($_POST['code'])) {
$verification_id = $_POST['verificationId'];
$code = $_POST['code'];

$verify_url = 'https://api.trustedaccounts.org/phone/YOUR_PUBLISHABLE_KEY/verify-code';
$verify_data = json_encode([
'verificationId' => $verification_id,
'code' => $code
]);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $verify_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $verify_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($http_code === 200) {
$result = json_decode($response, true);

if ($result['success']) {
echo json_encode([
'success' => true,
'message' => 'Phone verified successfully',
'phone' => $result['phone']
]);
} else {
http_response_code(400);
echo json_encode([
'success' => false,
'error' => $result['error']
]);
}
} else {
http_response_code(500);
echo json_encode(['error' => 'Verification service unavailable']);
}
}
?>

πŸ“Š Verification Results​

The API returns detailed verification results:

{
"success": true,
"verificationId": "ver_1234567890",
"phone": "+1234567890",
"country": "US",
"carrier": "Verizon",
"type": "mobile",
"status": "verified",
"timestamp": "2024-01-15T10:30:00Z"
}

🌍 Global Coverage​

  • 200+ Countries: Worldwide phone number support
  • Multiple Carriers: All major mobile and landline providers
  • International Format: Automatic country code detection
  • Local Numbers: Support for local number formats

🎯 Use Cases​

  • Account Security: Two-factor authentication
  • Registration: Prevent fake account creation
  • Password Reset: Secure password recovery
  • Transaction Verification: High-value transaction confirmation
  • Identity Verification: KYC compliance

πŸ“ˆ Best Practices​

  1. User Experience: Provide clear instructions and error messages
  2. Rate Limiting: Implement appropriate rate limiting
  3. Fallback Methods: Provide alternative verification methods
  4. Security: Store verification IDs securely
  5. Testing: Test with real phone numbers

Ready to implement? Get your publishable key from the Developer Console and start verifying phone numbers!