Reputation: 1
I want to validate pakistani mobile number in my php registration form. I need a regular expression that validate all the pakistani numbers (zong, ufone, telenore, jazz, warid) e.g 03337800766
or +923124432876
^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$
I used this code but its not working
if(!preg_match("/^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/", $mobile)){
echo "Mobile number is valid";
}
There is not any error but it show no effect our any number
Upvotes: 0
Views: 958
Reputation: 1
Regular expression to validate the Pakistan Mobile number
^((+92|0092||92|0){1}(3)[0-9]{9})$|^(((+92|0092|92){1}((\s?)|(-?))(3)|(03))[0-9]{2}((\s?)|(-?))[0-9]{7})$
Example:
03457172848 Valid
0345-7172848 Valid
0345 7172848 Valid
345-7172848 NOT Valid
-345-7172848 NOT Valid
034571-72848 NOT Valid
0-3457172848 NOT Valid
+923457172848 Valid
00923457172848 Valid
923457172848 Valid
920457172848 NOT Valid
92-345-7172848 Valid
92 345 7172848 Valid
92-0345-7172848 NOT Valid
(+92)3457172848 NOT Valid
Upvotes: 0
Reputation: 34
You can use this format:
^((\+923|923|03)(([0-4]{1}[0-9]{1})|(55)|(64))[0-9]{7})$
If a user puts "0378 XXXXXXX", we know that this one number is not valid in Pakistan. As a user puts "0300-0309/0310-0319/0320-0329/0330-0339/0340-0349/0355/0364", these are only valid phone numbers in Pakistan.
Upvotes: 1
Reputation: 45
Its as simple as
**/^923\d{9}$|^03\d{9}$/**
This code will validate both type of numbers with 923 or with 03 if you need to validate +923 then use following code.
**/^+923\d{9}$|^923\d{9}$|^03\d{9}$/**
Thanks
Upvotes: 0
Reputation: 119
you made a mistake, try ^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$
The "+" need to be escaped
Upvotes: 1