wire.validate
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.
Parameters
Config Properties
Use the following properties on the second parameter config
to configure the validation.
Validation Types
The following details the valid values of the type configuration property along with the additional configuration for each.
Number
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.
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
.
Date
Use the date
type to verify that a value is a valid date.
Phone Number
Use the phone
type to verify a value is a valid phone number.
Email Address
Use the email
type to verify that a value is a valid email address.
Regular Expression
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.
Custom
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.
Value
When using the custom
validation type, the value passed in can also be an object.
Last updated