Last active
December 2, 2021 08:38
-
-
Save gklein/5309212da89a5c5b936746ff0cf8acf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (function() { var re = /^\+?(972|0)(\-)?0?([5]{1}\d)\-?(\d{7})$/; var val=prompt("Phone Number #","");var phone=val.replace(re,'972$3$4');location="https://wa.me/"+escape(phone);})() |
Thank you, @gklein!
I wrote my version of phone processing — https://gist.github.com/baslie/6091c3e5bc1439e3b3c3e33b8bfafee2.
The bookmarklet works as follows:
- Save the code in bookmarks, for example as "Phone to WhatsApp".
- Highlight the phone number on the page.
- Press "Phone to WhatsApp".
The only thing I need help is how to validate the phone number. I need the script to add the missing prefixes itself (e.g. country codes).
You can use replace() with a regular expression in order to adapt the phone number to the required format.
Yeap, of course :) I need more practice with REGEXPs
Try this one:
https://www.youtube.com/watch?v=ZfQFUJhPqMM
Good luck.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeap, of course :) I need more practice with REGEXPs