jQuery http://jquery.com/download/
<script type="text/javascript" src="./js/iqwik-validator.min.js"></script>
Add data-attributes to fields
example:
<input type="text" data-req="true" data-err-text="Field is required">
<input type="text" data-req="true" data-type="name" data-err-text="Name is required">
<input type="text" data-req="true" data-type="phone" data-err-text="Phone is required">
<input type="text" data-req="true" data-type="email" data-err-text="E-mail is required">
$('#form').iqwikValidator();
and styles...
.error-border {
border-color: red;
}
.error {
color: red;
}
Name | Type | Description |
---|---|---|
data-req | Boolean | true => required |
data-type | String | text, name, phone, email (default type = text) for type of validation |
data-err-text | String | Your error text |
data-err-class | String | attribute "name" |
You may change default patterns
Name | Pattern/Type | Description |
---|---|---|
text | /^([\S]{1,}).+/i | |
name | /^[а-яА-ЯёЁa-zA-Z]{2,}$/i | |
phone | /^\+7[-]\d{3}[-]\d{3}[-]\d{4}$/ | |
/^\w+([\.-]?\w+)*@(((([a-z0-9]{2,})|([a-z0-9][-][a-z0-9]+))[\.][a-z0-9])|([a-z0-9]+[-]?))+[a-z0-9]+\.(org|com|co|net|io|ru)$/i | ||
errorClass | Boolean | change default selector for error class, should be FALSE (default => TRUE) |
onSubmit | Fuction | add event on submit form |
example:
$('#form').iqwikValidator({
text: /^([\w|\d]|\s){3,}$/i,
errorClass: false,
onSubmit: function(e){
alert($(e).serialize());
}
});