Skip to content

Commit

Permalink
simplify with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Aug 28, 2023
1 parent a7e8978 commit 3037334
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions components/app/modals/add-edit-domain-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ function AddEditDomainModal({
name="domain"
id="domain"
required
autoFocus
autoComplete="off"
pattern="[[\p{Letter}\p{Mark}\d-.]+"
className={`${
Expand Down
6 changes: 2 additions & 4 deletions lib/api/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ export const validateDomain = async (
}
const validDomain =
validDomainRegex.test(domain) &&
domain !== "dub.co" &&
!domain.endsWith(".dub.co") &&
domain !== "dub.sh" &&
!domain.endsWith(".dub.sh");
// make sure the domain doesn't contain dub.co/dub.sh
!/^(dub\.co|.*\.dub\.co|dub\.sh|.*\.dub\.sh)$/i.test(domain);

if (!validDomain) {
return "Invalid domain";
Expand Down

0 comments on commit 3037334

Please sign in to comment.