Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #265 from threefoldtech/development_adding-domain-…
Browse files Browse the repository at this point in the history
…name-validator

Adding regex domain name validator
  • Loading branch information
xmonader authored Dec 16, 2021
2 parents bf32032 + c5980d7 commit bc1d231
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/elements/caprover/Caprover.wc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import Modal from "../../components/DeploymentModal.svelte";
import hasEnoughBalance from "../../utils/hasEnoughBalance";
import validateName from "../../utils/validateName";
import validateDomainName from "../../utils/validateDomainName";
const data = new Caprover();
let loading = false;
Expand All @@ -39,11 +40,11 @@
{ label: "CPU", symbol: "cpu", placeholder: "CPU", type: "number" },
{ label: "Memory (MB)", symbol: 'memory', placeholder: "Memory in MB", type: "number" },
{ label: "Disk Size (GB)", symbol: "diskSize", placeholder: "Disk size in GB", type: "number" },
{ label: "Domain", symbol: "domain", placeholder: "domain configured in your name provider.", type: "text" },
{ label: "Domain", symbol: "domain", placeholder: "domain configured in your name provider.", type: "text", validator: validateDomainName, invalid: false },
{ label: "Password", symbol: "password", placeholder: "Caprover new password", type: "text" },
];
$: disabled = ((loading || !data.valid) && !(success || failed)) || !profile || status !== "valid" || fields[0].invalid; // prettier-ignore
$: disabled = ((loading || !data.valid) && !(success || failed)) || !profile || status !== "valid" || fields[0].invalid || fields[4].invalid; // prettier-ignore
let message: string;
let modalData: Object;
async function deployCaproverHandler() {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/validateDomainName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// regex patter for validating domain name
const DOMAIN_NAME_REGEX = /^\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b$/

// prettier-ignore
export default function validateDomainName(domain: string): string | void {
if (!DOMAIN_NAME_REGEX.test(domain)) return "Domain name is not valid";
}

0 comments on commit bc1d231

Please sign in to comment.