1.3.0 • Published 8 years ago

awkward-validator v1.3.0

Weekly downloads
2
License
UNLICENSED
Repository
github
Last release
8 years ago

#Awkward Validator

Oscar and Owl's custom (albeit limited) form validation tool. If any changes are made, please ensure full code coverage.

This module modifies the array of objects given in the data parameter. data.property.error can be used to display input errors to the user.

var av = require('awkward-validator');

var data = [{
      name: {
        value: '',
        placeholder: '',
        error: 'Please enter a different name',
        valid: true
      },
      mobile_number: {
        value: '',
        placeholder: '',
        error: 'Invalid phone number',
        valid: true
      },
      email_address: {
        value: '',
        placeholder: '',
        error: 'Invalid email address',
        valid: true
      }
    }];

    var schema = {
      type: 'array',
      items: {
        properties: {
          name: {
            properties: {
              value: {
                type: 'string',
                minLength: 2,
                maxLength: 50
              }
            }
          },
          mobile_number: {
            properties: {
              value: {
                type: 'string',
                minLength: 11,
                maxLength: 15
              }
            }
          },
          email_address: {
            properties: {
              value: {
                type: 'string',
                pattern: '^\\S+@\\S+$',
              }
            }
          }
        }
      }
    }

    var result = av.validate(data, schema);

    if(!result) {
      throw new Error();
    }

    // Submit form
1.3.0

8 years ago

1.2.9

8 years ago

1.2.8

8 years ago

1.2.7

8 years ago

1.2.5

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.1.0

8 years ago