validate3

validates values against a predefined set of regexps.

Usage no npm install needed!

<script type="module">
  import validate3 from 'https://cdn.skypack.dev/validate3';
</script>

README

validate

validates values against a predefined set of regexps.

usage

try {
  validate('some value', 3.5, 'int');
} catch(e) {
  // e.type, e.val, e.key
}

// or an array of values
validate([1, 2, 3], 'int_array');

Note that validate always escapes html & collapses whitespaces before testing anything.

Actual tested value will be returned upon a successful validation.

api

validate(key, val, type)

key is optional, if set it will be thrown along with an Exception.

type should be one of the following:

These are the regular expressions exposed by the regexps module:

  • email
  • url
  • cc
  • urlsafe
  • username
  • numeric
  • alpha
  • alphanumeric
  • password
  • creditcard
  • guid
  • date
  • int
  • double

If given type name ends with _array, val will be treated as an array.

License

The MIT License (MIT)

Copyright (c) 2014 Onur Gunduz ogunduz@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.