🔍Regex Recipes
Serbian Phone Numbers
Validate Serbian phone numbers with local format patterns.
Pattern
^(\+381|0)[1-9]\d{7,8}$Explanation
Matches Serbian numbers: +381 or 0, followed by non-zero digit, then 7-8 more digits.
Examples
Mobile +381
Input
+381641234567
Output
✓ Match (9 digits after 381)
Mobile local
Input
0641234567
Output
✓ Match
Landline Belgrade
Input
0112345678
Output
✓ Match (8 digits after 0)
Invalid - wrong prefix
Input
381641234567
Output
✗ No match (missing +)
Code Examples
JavaScript
const serbianPhoneRegex = /^(\+381|0)[1-9]\d{7,8}$/;
function validateSerbianPhone(phone) {
// Remove spaces and dashes
const cleaned = phone.replace(/[\s-]/g, '');
return serbianPhoneRegex.test(cleaned);
}
// Convert to international format
function toInternational(phone) {
const cleaned = phone.replace(/[\s-]/g, '');
if (cleaned.startsWith('0')) {
return '+381' + cleaned.substring(1);
}
return cleaned;
}Try it Now
💡 Tips
- Strip spaces and dashes before validation
- Mobile codes: 06x (x = 0-9)
- Belgrade landline: 011
- Convert to E.164 for storage
⚠️ Common Pitfalls
- Mobile numbers have 9 digits, landlines have 8
- Users may enter with spaces: 064 123 4567
- Old numbering plan may have different lengths
- International format +381 vs local 0