1.0.8 • Published 3 years ago

formvalidationts v1.0.8

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Introduction

Form Validation is a quick way of identifying and validating forms when submitting a form. There are two ways you can validate the form, manually 1-by-1 or via the form element.

Validation 1-by-1

You start off with setting up an array of ID to check

const inputs = ['full_name', 'reg_email', 'reg_phone', 'first_line', 'post_code']

Then you initialise the class using the following code:

const parser = new ValidateForm()
let validatedCount = 0
inputs.forEach((item) => {
const parsedData: any = parser.parse(<HTMLInputElement>document.getElementById(item))
if (parsedData.status) {
    validatedCount++
}
})

This will then verify all the fields and let you know which one has errors, it will also inject css classes to the failed or validated form fields. The defaults CSS classes are valid is-valid and invalid is-invalid.

Validate all fields in the form

// element.target is the Input element
const form: HTMLInputElement = element.target
const parser = new ValidateForm()
parser.parse(form)

Types of validation

length of field:

<input....
data-validate="length"
data-value="3"
.../>

Email address:

<input....
data-validate="email"
data-value="0"
.../>

Phone Number address:

<input....
data-validate="phoneNumber"
data-value="0"
.../>
1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago