isValidOrgSlug.tsx 584 B

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