I am using the following regex for validating Group Links For WhatsApp url’s.
JavaScript
x
$regex = '/^(https?://)?chat(?:.whatsapp.com/)([a-zA-Z0-9_-]{22})$/';//its working for without 'invite'
I want the regex to support the following URL formats:
JavaScript
https://chat.whatsapp.com/FrTz7HJfmKjAROYZsfDrKQ
https://chat.whatsapp.com/invite/FrTz7HJfmKjAROYZsfDrKQ
Advertisement
Answer
You can try this:
JavaScript
^(https?://)?chat.whatsapp.com/(?:invite/)?([a-zA-Z0-9_-]{22})$
(?:invite/)?
makes the invite/
block optional.