Phone and Email Validation
Note: Carriyo performs static validation of phone numbers and email addresses to reduce errors during shipment booking and notification. However, we strongly recommend that you implement these validations upfront during the order capture process to prevent issues before they occur.
To ensure reliable delivery and seamless post-purchase communication, it is essential to provide valid email addresses and phone numbers when creating orders or shipments in Carriyo. Accurate contact details help avoid delivery failures and ensure that customers receive important notifications.
Implementing proper validation at the order capture stage—such as during e-commerce checkout—is a best practice for data hygiene and delivery success.
📞 Phone Number Validation
The best way to perform phone number validation is through static validation—verifying whether a number is correctly formatted, valid for the specified country, and structurally sound. This does not check whether the number is reachable or active.
✅ Google's libphonenumber
libphonenumber
is the industry standard for validating and formatting phone numbers. Originally developed by Google for Android, it is now widely used across global platforms.
🔍 Try It Out: Interactive phone validator
(Third-party tool using Google's libphonenumber
library)
🔹 Key Features
- Validates phone numbers for all countries
-
Detects:
- Correct international/national formats
- Number length
- Mobile vs landline vs toll-free numbers
- Normalizes numbers into formats like E.164 , national , or international
🔹 Limitations
- It does not verify if a number is active or reachable .
- It's purely syntactic and structural validation.
🛠 Libraries by Platform
Platform | Library | Description |
---|---|---|
JavaScript | libphonenumber-js | Lightweight, ideal for web |
Java | libphonenumber | Official Java port |
Python | phonenumbers | Full-featured Python port |
PHP | libphonenumber-for-php | Complete PHP implementation |
Front-end UI | intl-tel-input | Includes country picker |
✳️ Example: JavaScript Validation with libphonenumber-js
import { parsePhoneNumberFromString } from 'libphonenumber-js'
const input = '+14155550132'
const phoneNumber = parsePhoneNumberFromString(input)
if (phoneNumber && phoneNumber.isValid()) {
console.log('Valid phone number:', phoneNumber.formatInternational())
} else {
console.log('Invalid phone number')
}
📧 Email Address Validation
For email validation, the goal is initially static validation—verifying that the email is properly formatted and syntactically correct according to RFC 5322. This ensures the email could be valid, but does not confirm if it is active or deliverable.
Since format validation alone does not guarantee deliverability, it is recommended to implement email verification by sending a confirmation email (e.g., with a verification link) to ensure the address is active and accessible by the customer.
⚠️ Important: Custom regex validation often produces false positives/negatives. Carriyo recommends using well-tested libraries for email address validation.
✅ Popular Libraries
Language | Library |
---|---|
JavaScript | validator.js |
Python | validate_email |
Java | Apache Commons Validator |
✅ Best Practices
- Validate email addresses and phone numbers both client-side and server-side .
- Store phone numbers in E.164 format for consistency.
- Use libraries that follow standards like RFC 5322 for emails and ITU-T E.164 for phone numbers.
- Don’t rely solely on regex—use well-maintained, purpose-built libraries.
- For email addresses, implement verification emails to confirm deliverability and ownership.