A JavaScript plugin that can be used completely without any other JavaScript code, but also can get extended by own code
cvalidate is a Custom Validator that valdates all your inputs and it automatically replaces the required attribute.
<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)
Add the data attribue data-cvalidate-class="HERE_YOUR_CLASS_NAME"
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
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
});
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!)