Hi all,
Today I'm going to share, how to populate WhatsApp link based on the seller number.
My example today is based on Malaysia's phone number.
The registration input doesn't have an input validator for the phone number, however, these are the most common number registered by users.
1) starting with 6 at front
2) starting with +6 at front
3) normal number without country code eg : 014xxxxxx
I introduced a simple pattern that has 2 groups.
The first pattern
The second pattern
If the number does not match these two patterns, we will append 6 in front of the number.
Hit me some comments if you encountered any issues. I will try to help out!
Image from Pexels |
Today I'm going to share, how to populate WhatsApp link based on the seller number.
My example today is based on Malaysia's phone number.
The registration input doesn't have an input validator for the phone number, however, these are the most common number registered by users.
1) starting with 6 at front
2) starting with +6 at front
3) normal number without country code eg : 014xxxxxx
Full code on how to populate whatsapp link for seller number
basically,I introduced a simple pattern that has 2 groups.
"#(^[6]\w*$)|(^[+][6]\w*$)#";
The patterns must have a delimeter added for PHP, in my case i use a `#`. You can use other delimiter that supported by PHP.
The first pattern
(^[6]\w*$)
Checks whether the seller phone number starts with number 6 and followed with other characters. If it is matched, do nothing as the format is already correct.
The second pattern
(^[+][6]\w*$)
Checks whether the seller phone number starts with a character '+' and followed by 6 and other characters. If it is matched, replace the '+' with empty string. As Whatsapp API does'nt accept '+' character.
If the number does not match these two patterns, we will append 6 in front of the number.
else {
$number = "6".$number;
}
Why? because that is the number format understand by WhatsApp API~
Hit me some comments if you encountered any issues. I will try to help out!
Comments
Post a Comment