WireBootstrap
HomeDocsBuySupport
  • Introduction
  • Overview
  • Getting Started
  • Installation
  • Connecting to Data
    • Data Connectors
      • SQL Data
      • Custom Web Services
      • Local Data
      • Other Sources
    • Data Sources
    • Discovery
    • Building a Data Connector
  • Working With Queries
    • Select Queries
      • Query Extensions
    • Stored Procedures
    • Custom Web Services
    • Executing Queries
    • ORM
  • Writing Data
  • Updates
  • Deletes
  • Working with DataTables
    • Introduction
    • Filter and Sort
    • Select and Calculate
    • Joins
    • Rows
    • Columns
  • Working with DataSets
  • Introduction
  • Executing Queries
  • Transforms
  • Writing Data
  • Data Events
  • Working with Components
    • Introduction
    • Encapsulation
    • Configuration
      • Data
      • Events
      • Observables
      • Validation
      • Display
      • Vendor
      • Custom
    • Component
    • Web Frameworks
    • Building a Component
      • Hello World
      • Data Events
      • DataSets
  • Working With Data Events
    • Introduction
    • Event Basics
    • Event Data
    • Event Actions
  • Working with Themes
    • Introduction
    • Sample Data
    • Libraries
    • Pages
    • Building a Theme Project
  • Utilities
    • Formatting
    • Expressions
    • Collections
    • Spinners
    • Copy and Merge
    • Validation
    • Loading Assets
    • Service Calls
    • Download Files
    • Browser Location
    • Types
    • Promise
  • Reference
    • wire
      • wire.Collection
      • wire.download
      • wire.validate
    • wire.data
      • wire.data.DataEvent
      • wire.data.DataModel
      • wire.data.DataPromise
      • wire.data.DataSet
      • wire.data.DataSource
      • wire.data.DataTable
        • Columns
        • Rows
      • wire.data.StoredProcedure
      • wire.data.TableQuery
    • wire.ui
      • wire.ui.Component
      • wire.ui.validate
Powered by GitBook
On this page
  • Parameters
  • Config Properties
  • Validation Types
  • Number
  • Value
  • Date
  • Phone Number
  • Email Address
  • Regular Expression
  • Custom

Was this helpful?

  1. Reference
  2. wire

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

Name

Description

value

The value to be validated.

config

The configuration for the validation.

Config Properties

Use the following properties on the second parameter config to configure the validation.

Name

Description

type

error

Error message to be returned if the validation fails.

required

Determines whether the value passed into the validate method is required.

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.

// returns null
const error = wire.validate(10, {    
    type: "number"
});

Use gt with the number type to be sure a value is greater than a specific value.

// returns value in error
const error = wire.validate(10, {    
    type: "number", 
    gt: 20
    error: "Please enter a number greater than 20"
});

Value

Use the value type to verify that a value is within a list of values.

// returns null
const error = wire.validate("Y", {    
    type: "value", 
    values: [ "Y", "N" ]
});

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.

// returns default error message for 'value' type
const error = wire.validate("y", {    
    type: "value", 
    case: true,
    values: [ "Y", "N" ]
});

Date

Use the date type to verify that a value is a valid date.

// returns null
const error = wire.validate("01-15-1986", {    
    type: "date" 
});

Phone Number

Use the phone type to verify a value is a valid phone number.

// returns null
const error = wire.validate("201-555-1212", {    
    type: "phone" 
});

Email Address

Use the email type to verify that a value is a valid email address.

// returns null
const error = wire.validate("jkratz@gmail.com", {    
    type: "email" 
});

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.

// returns null
const error = wire.validate("201-555-1212", {    
    type: "regex",
    exp: "^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$" 
});

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.

// returns null
const error = wire.validate("011586", {    
    type: "custom" 
    validate: (value, config) => {
        if(!moment(value, 'MMDDYY', true).isValid())
            return "Must be in format 'mmddyy' (i.e. 081587)";
    }
});

Value

When using the custom validation type, the value passed in can also be an object.

const data = {date: "011586", checkMe: false };

const error = wire.validate(data, {    
    type: "custom" 
    validate: (value, config) => {
        if(value.checkMe && !moment(value.date, 'MMDDYY', true).isValid())
            return "Must be in format 'mmddyy' (i.e. 081587)";
    }
});
Previouswire.downloadNextwire.data

Last updated 1 year ago

Was this helpful?

The type of validation to be performed. See valid values .

Note, the site is a useful site for testing regular expressions for use with this type of validation.

The following uses the library to do a custom date validation.

https://www.regextester.com/
moment.js
below