Giter Club home page Giter Club logo

valid.js's Introduction

Build Status Coverage Status Code Climate

A library for data validation.

Install

ValidateJS is available on npm:

npm install valid.js --save

or bower:

bower install valid.js

Usage

With ES6/import

import {validate, string, util, isValid} from 'valid.js'

let testIsValid = validate(string.maxLength(15), util.isRequired)
let result = testIsValid('Test ValidateJS')
// result => true

// or using the 'isValid' shorthand method
let result = isValid('Test ValidateJS', [string.maxLength(15), util.isRequired])
// result => true

With require

var validatejs = require('valid.js')
var validate = validatejs.validate,
    isValid = validatejs.isValid,
    string = validatejs.string,
    util = validatejs.util

var testIsValid = validate(string.maxLength(15), util.isRequired)
var result = testIsValid('Test ValidateJS')
// result => true

// or using the 'isValid' shorthand method
var result = isValid('Test ValidateJS', [string.maxLength(15), util.isRequired])
// result => true

With Browser

<script src="./bower_components/valid.js/dist/validate.js"></script>
var validate = validate.validate
var string = validate.string
var util = validate.util

var testIsValid = validate(string.maxLength(15), util.isRequired)
var result = testIsValid('Test ValidateJS')
// result => true

OR

var validate = window.validate.validate
var string = window.validate.string
var util = window.validate.util

var testIsValid = validate(string.maxLength(15), util.isRequired)
var result = testIsValid('Test ValidateJS')
// result => true

OR

var isValid = window.validate.isValid
var string = window.validate.string
var util = window.validate.util

var result = isValid('Test ValidateJS', [string.maxLength(15), util.isRequired])
// result => true

Also available for AMD

Validation Functions

  • String
    • isString
    • minLength(min)
    • maxLength(max)
    • length(min, max)
    • regex(reg)
  • Number
    • isNumber
    • minNumber
    • maxNumber
    • between
  • Date
    • isDate
    • minDate(min)
    • maxDate(max)
    • between(min, max)
  • Bool
    • isTrue
    • isFalse
  • Util
    • isRequired
    • isEmail
    • isCep
    • isUrl
    • isHexColor
    • isCpf
    • isCnpj
  • Credit Card
    • isVisa
    • isElo
    • isHipercard
    • isMasterCard
    • isDiners
    • isAmex
    • isCreditCard

Contributing

Send us a Pull Request! Here is how:

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Stage your changes: git add .
  4. Commit your changes: git commit -m 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request

LICENSE

The MIT License (MIT)

Copyright (c) 2015 Daniel Leite de Oliveira

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.

valid.js's People

Contributors

arkni avatar danilowoz avatar dleitee avatar efexen avatar greenkeeper[bot] avatar karlprieb avatar lucasferreira avatar mii9000 avatar minerado avatar rdiego26 avatar sartoshi-foot-dao avatar sciotta avatar sergiors avatar smaniotto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

valid.js's Issues

What is the name of the library?

Hi, cool library.. Just wondering... the GitHub URL for this is "valid.js" but the actual name on the README says "validate.js". Is that a mistake? Which is the real name?

NPM install fails when use ES6 import

Hi @dleitee

I'm trying to use the ES6 import without sucess:

import {validate, string, util, isValid} from 'valid.js'

The problem (I guess) is the version that are publish at npm registry doesn't contain dist folder inside of them. In fact, dist/validate.js file is important because they are set as main script inside package.json file.

.....
"repository": {
    "type": "git",
    "url": "git+https://github.com/dleitee/valid.js.git"
  },
  "main": "dist/validate.js", // <--- this line...
......

Can you please help? I think that you need is just update npm registry with a new version of package.

Thanks!

Trying to get in touch regarding a security issue

Hey there!

I'd like to report a security issue but cannot find contact instructions on your repository.

If not a hassle, might you kindly add a SECURITY.md file with an email, or another contact method? GitHub recommends this best practice to ensure security issues are responsibly disclosed, and it would serve as a simple instruction for security researchers in the future.

Thank you for your consideration, and I look forward to hearing from you!

(cc @huntr-helper)

Tests

  • Validate
  • String
    • isString
    • minLength
    • maxLength
  • Number
    • maxNumber
    • minNumber
    • between
    • isNumber
  • Util
    • required
  • Boolean
    • isTrue
    • isFalse
  • lib/reduce
  • lib/isnil
  • import validate from '../dist/validate'
  • var validate = require('../dist/validate')
  • window.validate (Browser)
  • validate (Browser/Global)

Proper email validation

It seems this email: test@a will be a valid email address.

console.log(isValid('test@a', util.isEmail))
// => true

Adaptar ao RFC

Mais uma implementação que não segue a RFC. Olhe essa implementação: ele valida todos os e-mails de acordo com a RFC, porém de maneira mais controlada, por exemplo dando a opção da parte local não requerer um TLD, o que é útil em vários casos.

Também ele permite e-mails como "[email protected]" por que e-mails assim são válidos pela RFC. Quem criou essa de que "+" significa uma label foi o Gmail. Se quiser filtrar usuários com isso só normalizar o e-mail, algo que a biblioteca permite.

O mais importante: essa implementação aceita, por padrão, e-mails internacionalizados. Caso talvez você não tenha um e-mail "josé[email protected]", mas isso não significa que no futuro e-mails assim sejam comuns. Em nossa língua isso até não é grande problema, mas e quanto a outras línguas onde tirar um acento muda todo o sentido da palavra? Por acaso o foco dessa biblioteca é só Brasil? (já que é CEP ao invés de "postalCode")

Agora, antes que pense que estou dizendo "largue essa aqui e use a outra", se conseguir fazer o mesmo, mostrando na documentação as diferentes (como "essa biblioteca trata apenas os casos mais comuns") e continuando simples, tudo bem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.