Instagram as per 2024 guidelines has introduced new requirements for the username, more can be seen in its official docs. If you are using it client side, and you want your regex to be compatible with both IOS and Android, you may use the following regex:
/^(?![0-9]+$)a-zA-Z0-9_{0,28}$/
To break it down:
- ^(?![0-9]+$): Ensures the username is not entirely numeric (iOS supports negative lookaheads at the start).
- [a-zA-Z0-9_]: Ensures the username starts with a letter, number, or underscore.
- (?:[a-zA-Z0-9_]*(?:.[a-zA-Z0-9_]+)?){0,28}$: Allows dots to appear but only when they are not consecutive. Restricts total
length to 30 characters.