Contact
Saudi Mobile Number Regex
Saudi mobile numbers start with 5 after the country code, giving nine digits in the national number, and are dialled domestically with a leading 0. This pattern accepts both the 05 domestic form and the +966 international form, with optional spaces or dashes between the usual groups. It is a good fit for delivery apps, e-commerce checkouts and OTP sign-up screens serving the Saudi market. The honest limit is that it accepts every 5x prefix, including ones not currently assigned to an operator, so it cannot tell whether a number is real.
Pattern (JavaScript)
/^(?:\+966[ -]?|0)5[0-9][ -]?[0-9]{3}[ -]?[0-9]{4}$/Starts at the start of the line/string, then (the text "+966", then one of the characters -, optionally (zero or one time) OR the character "0"), then the character "5", then a digit, then one of the characters -, optionally (zero or one time), then a digit, exactly 3 times, then one of the characters -, optionally (zero or one time), then a digit, exactly 4 times, then the end of the line/string.
Limit: Checks the format only; it cannot tell whether the number is active.
Examples
Matches
- ✓ +966 50 123 4567
- ✓ 0591234567
- ✓ +966512345678
Does not match
- ✗ 0451234567
- ✗ +966 40 123 4567
- ✗ 05912345
Try it
0 matches (JavaScript engine)
+966 50 123 4567
0591234567
+966512345678
0451234567
+966 40 123 4567
05912345Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(?:\+966[ -]?|0)5[0-9][ -]?[0-9]{3}[ -]?[0-9]{4}$/g;
const text = "+966 50 123 4567";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(?:\+966[ -]?|0)5[0-9][ -]?[0-9]{3}[ -]?[0-9]{4}$')
text = '+966 50 123 4567'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^(?:\+966[ -]?|0)5[0-9][ -]?[0-9]{3}[ -]?[0-9]{4}$/';
$text = '+966 50 123 4567';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^(?:\\+966[ -]?|0)5[0-9][ -]?[0-9]{3}[ -]?[0-9]{4}$");
String text = "+966 50 123 4567";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:\+966[ -]?|0)5[0-9][ -]?[0-9]{3}[ -]?[0-9]{4}$`)
text := "+966 50 123 4567"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(?:\+966[ -]?|0)5[0-9][ -]?[0-9]{3}[ -]?[0-9]{4}$");
var text = "+966 50 123 4567";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^(?:\+966[ -]?|0)5[0-9][ -]?[0-9]{3}[ -]?[0-9]{4}$").unwrap();
let text = "+966 50 123 4567";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(?:\+966[ -]?|0)5[0-9][ -]?[0-9]{3}[ -]?[0-9]{4}$/
text = '+966 50 123 4567'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why must the number start with 5 after the prefix?
- Saudi mobile ranges all start with 5, while landlines use area codes such as 11 for Riyadh. Requiring 5 keeps landlines out of mobile-only fields.
- Should I keep the leading 0 when storing?
- Store the E.164 form, which drops the 0 and adds +966. That form works with SMS gateways and avoids ambiguity when numbers are shared across countries.
- Does the pattern accept 00966?
- Not as written. Replace a leading 00 with + before testing, or add 00966 as an extra alternative in the first group.