1.0.2 • Published 1 year ago

form-part-validator v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

FORM PART VALIDATOR

The validator allows you to specify easily what each input should contain to be valid you can then watch for errors :

import Validator from "./validator.js";

const validator = new Validator();
validator.watch(document.querySelectorAll("input"));

you simply add a keyword to it's data-form-constraints attribute, separated by spaces :

<input type="text" name="foo" data-form-constraints="length:0:38 nodot nowhitespace nonumber">

this will, when using the watch function, produce an error badge when the input doesn't match it's constraints

CONSTRAINTS

namefunctionusage
lengthassert length between min and maxlength:min:max
minLengthassert minimum lengthminLength:min
maxLengthassert maximum lengthmaxLength:max
textassert value contains some texttext
uppercaseassert value is uppercaseuppercase
lowercaseassert value is lowercaselowercase
numberassert value is numbersnumber
nodotassert value has not dotsnodot
nowhitespaceassert value whitspacenowhitespace
nonumberassert value contains no numbersnonumber
emailassert value looks like an emailemail
dateInPastassert the date is x years:months:days in the pastdateInPast:year:month:day
dateInFutureassert the date is x years:months:days in the futuredateInPast:year:month:day

MUST HAVE

the name attribute is necessary for error messages to work properly

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago