isValidOrgSlug.tsx 621 B

12345678910111213141516171819
  1. // The isValidOrgSlug function should match the behaviour of this regular expression:
  2. // ^(?![0-9]+$)[a-zA-Z0-9][a-zA-Z0-9-]*(?<!-)$
  3. // See: https://bugs.webkit.org/show_bug.cgi?id=174931
  4. //
  5. // The ^(?![0-9]+$)[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$ regex should almost match the above regex.
  6. const ORG_SLUG_REGEX = new RegExp('^(?![0-9]+$)[a-zA-Z0-9][a-zA-Z0-9-]*$');
  7. function isValidOrgSlug(orgSlug: string): boolean {
  8. return (
  9. orgSlug.length > 0 &&
  10. !orgSlug.startsWith('-') &&
  11. !orgSlug.endsWith('-') &&
  12. !orgSlug.includes('_') &&
  13. ORG_SLUG_REGEX.test(orgSlug)
  14. );
  15. }
  16. export default isValidOrgSlug;