| Class name | Type | Description |
|---|---|---|
validator |
Component | For input, select, textarea |
validator-hint |
Part | for the hint text that appears after the input if it's invalid |
<input class="input validator" type="email" required="" placeholder="mail@site.com" />
Validator(const [], classes: 'input', placeholder: 'mail@site.com', required: true, type: 'email');
validator-hint class will be invisible if it comes after a validator class, then if the input is invalid, validator-hint will get visible. validator-hint will be visible if any previous (sibling) invalid validator element is present - wrap the elements (eg. in fieldset) to only show the hint for one invalid input. validator-hint still occupies space even if it's invisible because we don't want a layout shift when the hint appears. If you prefer to hide the hint when it's not visible, add hidden class to validator-hint. It will take no space when it's hidden, and if input is invalid, it will appear and take space.
<input class="input validator" type="email" required="" placeholder="mail@site.com" />
<div class="validator-hint">Enter valid email address</div>
Component.fragment([
Validator(const [], classes: 'input', placeholder: 'mail@site.com', required: true, type: 'email'),
div([Component.text('Enter valid email address')], classes: 'validator-hint'),
]);
<input type="password" class="input validator" required="" placeholder="Password" minlength="8" pattern="(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must be more than 8 characters, including number, lowercase letter, uppercase letter" />
<p class="validator-hint">
Must be more than 8 characters, including
<br />
At least one number
<br />
At least one lowercase letter
<br />
At least one uppercase letter
</p>
Component.fragment([
Validator(
const [],
classes: 'input',
placeholder: 'Password',
required: true,
type: 'password',
attributes: {
'minlength': '8',
'pattern': '(?=.*\\\\d)(?=.*[a-z])(?=.*[A-Z]).{8,}',
'title': 'Must be more than 8 characters, including number, lowercase letter, uppercase letter',
},
),
ValidatorHint(
[
Component.text('Must be more than 8 characters, including'),
br(),
Component.text('At least one number'),
br(),
Component.text('At least one lowercase letter'),
br(),
Component.text('At least one uppercase letter'),
],
),
]);
<input type="text" class="input validator" required="" placeholder="Username" pattern="[A-Za-z][A-Za-z0-9\\-]*" minlength="3" maxlength="30" title="Only letters, numbers or dash" />
<p class="validator-hint">
Must be 3 to 30 characters
<br />containing only letters, numbers or dash
</p>
Component.fragment([
Validator(
const [],
classes: 'input',
placeholder: 'Username',
required: true,
type: 'text',
attributes: {
'pattern': '[A-Za-z][A-Za-z0-9\\\\-]*',
'minlength': '3',
'maxlength': '30',
'title': 'Only letters, numbers or dash',
},
),
ValidatorHint(
[
Component.text('Must be 3 to 30 characters'),
br(),
Component.text('containing only letters, numbers or dash'),
],
),
]);
<input type="tel" class="input validator tabular-nums" required="" placeholder="Phone" pattern="[0-9]*" minlength="10" maxlength="10" title="Must be 10 digits" />
<p class="validator-hint">Must be 10 digits</p>
Component.fragment([
Validator(
const [],
classes: 'input tabular-nums',
placeholder: 'Phone',
required: true,
type: 'tel',
attributes: {
'pattern': '[0-9]*',
'minlength': '10',
'maxlength': '10',
'title': 'Must be 10 digits',
},
),
ValidatorHint([Component.text('Must be 10 digits')]),
]);
<input type="url" class="input validator" required="" placeholder="https://" value="https://" pattern="^(https?://)?([a-zA-Z0-9]([a-zA-Z0-9\-].*[a-zA-Z0-9])?\.)+[a-zA-Z].*$" title="Must be valid URL" />
<p class="validator-hint">Must be valid URL</p>
Component.fragment([
Validator(
const [],
classes: 'input',
placeholder: 'https://',
required: true,
type: 'url',
attributes: {
'value': 'https://',
'pattern': '^(https?://)?([a-zA-Z0-9]([a-zA-Z0-9\\-].*[a-zA-Z0-9])?\\.)+[a-zA-Z].*\$',
'title': 'Must be valid URL',
},
),
ValidatorHint([Component.text('Must be valid URL')]),
]);
<input type="date" class="input validator" required="" placeholder="Pick a date in 2025" min="2025-01-01" max="2025-12-31" title="Must be valid URL" />
<p class="validator-hint">Must be 2025</p>
Component.fragment([
Validator(
const [],
classes: 'input',
placeholder: 'Pick a date in 2025',
required: true,
type: 'date',
attributes: {
'min': '2025-01-01',
'max': '2025-12-31',
'title': 'Must be valid URL',
},
),
ValidatorHint([Component.text('Must be 2025')]),
]);
<input type="number" class="input validator" required="" placeholder="Type a number between 1 to 10" min="1" max="10" title="Must be between be 1 to 10" />
<p class="validator-hint">Must be between be 1 to 10</p>
Component.fragment([
Validator(
const [],
classes: 'input',
placeholder: 'Type a number between 1 to 10',
required: true,
type: 'number',
attributes: {
'min': '1',
'max': '10',
'title': 'Must be between be 1 to 10',
},
),
ValidatorHint([Component.text('Must be between be 1 to 10')]),
]);
<input type="checkbox" class="checkbox validator" required="" title="Required" />
<p class="validator-hint">Required</p>
Component.fragment([
Validator(
const [],
classes: 'checkbox',
required: true,
type: 'checkbox',
attributes: {'title': 'Required'},
),
ValidatorHint([Component.text('Required')]),
]);
<input type="checkbox" class="toggle validator" required="" title="Required" />
<p class="validator-hint">Required</p>
Component.fragment([
Validator(
const [],
classes: 'toggle',
required: true,
type: 'checkbox',
attributes: {'title': 'Required'},
),
ValidatorHint([Component.text('Required')]),
]);
<form>
<select class="select validator" required="">
<option disabled="" selected="" value="">Choose:</option>
<option>Tabs</option>
<option>Spaces</option>
</select>
<p class="validator-hint">Required</p>
<button class="btn" type="submit">Submit form</button>
</form>
form(
[
Select(
[
option([Component.text('Choose:')], value: '', selected: true, disabled: true),
option([Component.text('Tabs')]),
option([Component.text('Spaces')]),
],
classes: 'validator',
attributes: {'required': ''},
),
ValidatorHint([Component.text('Required')]),
Btn([Component.text('Submit form')], type: 'submit'),
],
);
<form class="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4">
<fieldset class="fieldset">
<label class="label">Email</label>
<input type="email" class="input validator" placeholder="Email" required="" />
<p class="validator-hint hidden">Required</p>
</fieldset>
<label class="fieldset">
<span class="label">Password</span>
<input type="password" class="input validator" placeholder="Password" required="" />
<span class="validator-hint hidden">Required</span>
</label>
<button class="btn btn-neutral mt-4" type="submit">Login</button>
<button class="btn btn-ghost mt-1" type="reset">Reset</button>
</form>
form(
[
Fieldset(
[
label([Component.text('Email')], classes: 'label'),
Validator(const [], classes: 'input', placeholder: 'Email', required: true, type: 'email'),
ValidatorHint([Component.text('Required')], classes: 'hidden'),
],
),
label(
[
span([Component.text('Password')], classes: 'label'),
Validator(
const [],
classes: 'input',
placeholder: 'Password',
required: true,
type: 'password',
),
span([Component.text('Required')], classes: 'validator-hint hidden'),
],
classes: 'fieldset',
),
Btn([Component.text('Login')], classes: 'mt-4', color: BtnColor.neutral, type: 'submit'),
Btn([Component.text('Reset')], classes: 'mt-1', style: [BtnStyle.ghost], type: 'reset'),
],
classes: 'fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4',
);