new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Mantine · all subjects

form/validators

12 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

isNotEmpty validator function

isNotEmpty checks that the form value is not empty. Empty string, empty array, false, null and undefined values are considered to be empty. Strings are trimmed before validation. The error message is optional.

isEmail validator function

isEmail uses the regular expression /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\..\w{2,})+$/ to determine whether the form value is a valid email address. The error message is optional.

matches validator function

matches checks whether the form value matches the given regular expression. If the form value is not a string, validation will fail. Takes a regexp pattern and an optional error message.

isInRange validator function

isInRange checks whether the form value is within the given min-max range. The first argument is an object with optional min and max properties. If the form value is not a number, validation will fail. The error message is optional.

hasLength validator function

hasLength checks whether the form value length is within the given min-max range. Works correctly with strings, arrays and any other objects that have a length property. Strings are trimmed before validation. Can accept either a single number for exact length, or an object with min and/or max properties. The error message is optional.

matchesField validator function

matchesField checks whether the form value is the same as the value in another form field. Takes the field name to compare against and an optional error message. Can only work with primitive values; arrays and objects cannot be compared.

isJSONString validator function

isJSONString checks whether the form value is a valid JSON string. Takes an optional error message.

isUrl validator function

isUrl checks whether the form value is a valid URL. By default, only http and https protocols are allowed and localhost is rejected. Takes an optional options object as the first argument with properties: allowLocalhost (boolean) to allow localhost URLs, and protocols (string array) to specify allowed protocols. The error message is optional.

isOneOf validator function

isOneOf checks whether the form value is included in the given list of allowed values. Uses strict equality for comparison. Takes an array of allowed values and an optional error message.

isNotEmptyHTML validator function

isNotEmptyHTML checks that the form value is not an empty HTML string. Empty string, string with only HTML tags and whitespace are considered to be empty. Takes an optional error message.

Validator functions optional error parameter

The last argument of all validator functions is optional. If the error is not set, then fields with failed validation will only have invalid styles without an error message.

Mantine form validators overview

The @mantine/form package exports several validation functions that can be used in validation rules objects. Validation functions are tiny in size and provide basic validation. For complex validation requirements, other types of validation should be used.

Give your agent this brain