[+] Input validation

pull/131/head
Azalea 2025-03-11 18:32:00 -04:00
parent c4e0717317
commit eb45075414
2 changed files with 6 additions and 3 deletions

View File

@ -3,11 +3,14 @@
export let value: string
export let placeholder: string
export let flex: number = 60
export let validate: (value: string) => boolean = () => true
</script>
<div class="field" style="flex: {flex}">
<label for={desc}>{desc}</label>
<input type="text" placeholder={placeholder} bind:value={value} id="{desc}" on:change />
<input type="text" placeholder={placeholder} bind:value={value} id="{desc}" on:change
class:error={value && !validate(value)}/>
</div>
<style lang="sass">

View File

@ -21,9 +21,9 @@
<!-- First input line -->
<div class="inputs">
<InputTextShort desc="Server Address" placeholder="e.g. http://aquadx.hydev.org"
bind:value={src.server} on:change />
bind:value={src.server} on:change validate={v => /^https?:\/\/[a-z0-9.-]+(:\d+)?$/i.test(v)} />
<InputTextShort desc="Keychip ID" placeholder="e.g. A0299792458"
bind:value={src.keychip} on:change />
bind:value={src.keychip} on:change validate={v => /^[A-Z0-9]{11}$/.test(v)} />
</div>
<!-- Second input line -->