chensenlai 10988628a0 语音房项目初始化 | 5 anni fa | |
---|---|---|
.. | ||
test | 5 anni fa | |
.jshintrc | 5 anni fa | |
.npmignore | 5 anni fa | |
.travis.yml | 5 anni fa | |
LICENSE | 5 anni fa | |
Makefile | 5 anni fa | |
README.md | 5 anni fa | |
bower.json | 5 anni fa | |
package.json | 5 anni fa | |
validator.js | 5 anni fa | |
validator.min.js | 5 anni fa |
A library of string validators and sanitizers.
Install the library with npm install validator
var validator = require('validator');
validator.isEmail('foo@bar.com'); //=> true
The library can be loaded either as a standalone script, or through an AMD-compatible loader
<script type="text/javascript" src="validator.min.js"></script>
<script type="text/javascript">
validator.isEmail('foo@bar.com'); //=> true
</script>
The library can also be installed through bower
$ bower install validator-js
matches('foo', /foo/i)
or matches('foo', 'foo', 'i')
.options
is an object which defaults to { protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, allow_underscores: false, host_whitelist: false, host_blacklist: false }
.options
is an object which defaults to { require_tld: true, allow_underscores: false }
.null
if the input is not a date.NaN
if the input is not a float.NaN
if the input is not an integer.'0'
, 'false'
and ''
returns true
. In strict mode only '1'
and 'true'
return true
.<
, >
, &
, '
and "
with HTML entities.keep_new_lines
is true
, newline characters are preserved (\n
and \r
, hex 0xA
and 0xD
). Unicode-safe in JavaScript.This library validates and sanitizes strings only. All input will be coerced to a string using the following rules
toString
property if available.null
, undefined
or NaN
with an empty string.input + ''
.You can add your own validators using validator.extend(name, fn)
validator.extend('isFinite', function (str) {
return isFinite(str);
});
Note that the first argument will be automatically coerced to a string.
validator.isFinite(12345); // => true
validator.isFinite('foo'); // => false
Version 3 of the library deprecated some functionality
If you're migrating from version 1.x
or 2.x
, check out the migration guide.
make test
- run the test suite.make test V=1
- run the test suite with added verbosity.make test TEST=pattern
- run tests that match a pattern.make coverage
- run a coverage analysis tool.make lint
- run a lint tool.Copyright (c) 2014 Chris O'Hara <cohara87@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.