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β
- User Experience: Provide clear instructions and error messages
- Rate Limiting: Implement appropriate rate limiting
- Fallback Methods: Provide alternative verification methods
- Security: Store verification IDs securely
- Testing: Test with real phone numbers
π Related Toolsβ
- Email Validation - Email verification
- User Validation - Identity verification
- Bot Detection - Automated traffic analysis
- Browser Fingerprinting - Device identification
Ready to implement? Get your publishable key from the Developer Console and start verifying phone numbers!