wire.validate
Last updated
Last updated
Validate data entered or selected by users using the wire.validate
method. The method will return null
if the validation was successful. It will return an error message if it was not.
Use the following properties on the second parameter config
to configure the validation.
The following details the valid values of the type configuration property along with the additional configuration for each.
Use the number
type to be sure a value is a valid number.
Use gt
with the number
type to be sure a value is greater than a specific value.
Use the value
type to verify that a value is within a list of values
.
Use case
with the value
type to specify whether the check against the values
list should be case sensitive. The case
condition defaults to false
.
Use the date
type to verify that a value is a valid date.
Use the phone
type to verify a value is a valid phone number.
Use the email
type to verify that a value is a valid email address.
Use the regex
type to verify that a value meets a regular expression condition. Set the expression into the exp
property.
The following checks for a valid phone number.
Note, the site https://www.regextester.com/ is a useful site for testing regular expressions for use with this type of validation.
When all else fails, use the custom
type to validate a value using a custom function. Use the validate
property to define the custom function. This function takes the same parameters as the validate
function itself and should return the same error if the validation is not successful.
The following uses the moment.js library to do a custom date validation.
When using the custom
validation type, the value passed in can also be an object.
Name
Description
value
The value to be validated.
config
The configuration for the validation.
Name
Description
type
The type of validation to be performed. See valid values below.
error
Error message to be returned if the validation fails.
required
Determines whether the value
passed into the validate
method is required.