Skip to content

Instantly share code, notes, and snippets.

@gklein
Last active December 2, 2021 08:38
Show Gist options
  • Save gklein/5309212da89a5c5b936746ff0cf8acf3 to your computer and use it in GitHub Desktop.
Save gklein/5309212da89a5c5b936746ff0cf8acf3 to your computer and use it in GitHub Desktop.
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);})()
@baslie
Copy link

baslie commented May 15, 2020

Thank you, @gklein!
I wrote my version of phone processing — https://gist.github.com/baslie/6091c3e5bc1439e3b3c3e33b8bfafee2.
The bookmarklet works as follows:

  1. Save the code in bookmarks, for example as "Phone to WhatsApp".
  2. Highlight the phone number on the page.
  3. 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

@gklein
Copy link
Author

gklein commented May 15, 2020

Thank you, @gklein!
I wrote my version of phone processing — https://gist.github.com/baslie/6091c3e5bc1439e3b3c3e33b8bfafee2.
The bookmarklet works as follows:

  1. Save the code in bookmarks, for example as "Phone to WhatsApp".
  2. Highlight the phone number on the page.
  3. 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