formxana

1.0.2 • Public • Published

Example usage

export default function Index() { const [formErrors, setFormErrors] = useState({}) let schema = { firstName: new xana().minlength(10).required().end(), lastName: new xana().minlength(10).required().end(), age: new xana().required().end(), }

const handleSubmit = (e) => { e.preventDefault() const errors = validateForm(e,schema) console.log(errors) setFormErrors ( errors ) }

return ( ) }

Simple form and validation

Primary usage

use validate() function to check validation of any object to your own rules. Rule attributes

Required : Array[0]

required :  [   true || false , 'default error message : required  ' 

allowedCharacters : [ [ 'abc' || 'ABC' || '123' || 'any symbol' || ] ] minlength : number maxlength : number

console.log(validate({ firstName: 'Nihat', lastName: 'Abdullazade' }, {

// firstName: { required: [true,'Required'], minlength: [3,'Minimum length is 3'], maxlength: [ 35 , ['Too long'], allowedCharacters: [  ['ABC', 'abc', '123', '_', '-'] , 'a' ] },
// lastName: { required: true, minlength: 3, maxlength: 35, allowedCharacters: ['ABC', 'abc', '123', '_', '-'] }

}))

Package Sidebar

Install

npm i formxana

Weekly Downloads

2

Version

1.0.2

License

ISC

Unpacked Size

6.59 kB

Total Files

3

Last publish

Collaborators

  • nihatxss