Skip to content
Advertisement

Regex for Group Links For WhatsApp URL [closed]

I am using the following regex for validating Group Links For WhatsApp url’s.

$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:

https://chat.whatsapp.com/FrTz7HJfmKjAROYZsfDrKQ
https://chat.whatsapp.com/invite/FrTz7HJfmKjAROYZsfDrKQ

Advertisement

Answer

You can try this:

^(https?://)?chat.whatsapp.com/(?:invite/)?([a-zA-Z0-9_-]{22})$

(?:invite/)? makes the invite/ block optional.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement