Giter VIP home page Giter VIP logo

cvalidate's Introduction

cvalidate

A JavaScript plugin that can be used completely without any other JavaScript code, but also can get extended by own code

jQuery is required (tested with jQuery-3.5.1)

The default required attribute alerts are annoying?

cvalidate is a Custom Validator that valdates all your inputs and it automatically replaces the required attribute.

How to use it with only HTML?

<form>
  <input class="checkbox" required type="checkbox"><br><br>
  <input class="email" required type="email"><br><br>
  <input class="tel" required type="tel"><br><br>
  <input class="url" required type="url"><br><br>
  <button>Send</button>
</form>

<script src="jQuery3.5.1.min.js"></script>
<script src="cvalidate.js"></script>

(Every input type which supports required got tested and worked with the script)

How to use custom classes instead of the default cval class?

Add the data attribue data-cvalidate-class="HERE_YOUR_CLASS_NAME"

I get problems because it searches a form-tag, but I want just the input without form

You can set exceptions to fix problems like that ... Just add the exceptions per data attribute. Multiple exceptions can be written with a comma. This Exceptions exist:

  • form-exception >> If input has no form, you can set this exception
  • event-exception >> If you want a custom event, set this as an exception

How can I build the validator into my own script?

If some features are missing, you can build your own script. To do that, you can use different functions:

CValException(element, exception); // This checks, if an exception is given or not. It returns true or false

CValGetForm(element); // This searches the closest form to an input element

CValValidate($('.example-input'), function(e)
{
    console.log(e.error) //e.error returns a custom error code (returns null if success == true)
    e.success == true // if element is validated
    e.success == false // if element is not validated / validation error
});

Which error codes could get returned by CValValidate(...)?

Error Codes:

  • TEXT_EMPTY
  • CHECKBOX_UNCHECKED
  • EMAIL_INVALID_FORMAT
  • NO_FILE_SELECTED
  • TELEPHONE_INVALID_FORMAT
  • URL_INVALID_FORMAT
  • null

If you find a problem or you have any question, feel free to contact me: Contact only on Discord: Fabian#3563 (Don't message me for fun!)

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.