update: allow ip-addresses and chrome extension ids.

This commit is contained in:
Darshan
2025-04-23 10:08:26 +05:30
parent 0cfe10c2ed
commit f6c7fd1bd2
4 changed files with 13 additions and 6 deletions
+7
View File
@@ -53,3 +53,10 @@ export function formatNum(number: number): string {
* Returns a regex to check hostname validity. Supports wildcards too!
*/
export const hostnameRegex = String.raw`(\*)|(\*\.)?(?!-)[A-Za-z0-9\-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,18}|localhost`;
/**
* Returns a regex to check hostname validity.
*
* Supports domains, localhost, wildcards, ip-addresses and Chrome extension IDs!
*/
export const extendedHostnameRegex = String.raw`(\*)|(\*\.)?((?!-)[A-Za-z0-9-]+([-.]{1}[a-z0-9]+)*\.[A-Za-z]{2,18}|localhost|(\d{1,3}\.){3}\d{1,3}|[a-z0-9]{32})`;
@@ -8,7 +8,7 @@
import { onMount } from 'svelte';
import { project } from '../../../store';
import { platform } from './store';
import { hostnameRegex } from '$lib/helpers/string';
import { extendedHostnameRegex } from '$lib/helpers/string';
let hostname: string = null;
@@ -50,7 +50,7 @@
id="hostname"
label="Hostname"
bind:value={hostname}
pattern={hostnameRegex}
pattern={extendedHostnameRegex}
patternError="Please enter a valid hostname"
placeholder="myapp.com" />
</FormList>
@@ -8,7 +8,7 @@
import { Submit, trackEvent } from '$lib/actions/analytics';
import { PlatformType } from '@appwrite.io/console';
import { isValueOfStringEnum } from '$lib/helpers/types';
import { hostnameRegex } from '$lib/helpers/string';
import { extendedHostnameRegex } from '$lib/helpers/string';
// enum Platform {
// Android = 'flutter-android',
@@ -174,7 +174,7 @@
placeholder={placeholder[platform].hostname}
tooltip={placeholder[platform].tooltip}
required
pattern={hostnameRegex}
pattern={extendedHostnameRegex}
patternError="Please enter a valid hostname"
bind:value={$createPlatform.hostname} />
@@ -8,7 +8,7 @@
import { createPlatform } from '../store';
import { Submit, trackEvent } from '$lib/actions/analytics';
import { PlatformType } from '@appwrite.io/console';
import { hostnameRegex } from '$lib/helpers/string';
import { extendedHostnameRegex } from '$lib/helpers/string';
const projectId = $page.params.project;
const suggestions = ['*.vercel.app', '*.netlify.app', '*.gitpod.io'];
@@ -60,7 +60,7 @@
placeholder="localhost"
tooltip="The hostname that your website will use to interact with the Appwrite APIs in production or development environments. No protocol or port number required."
required
pattern={hostnameRegex}
pattern={extendedHostnameRegex}
patternError="Please enter a valid hostname"
bind:value={$createPlatform.hostname} />