daformcheck automatically validates any HTML forms that have been given a class of "da-validate".

It can be used as a fall back for browsers that do not support HTML5 validation, or to perform additional/custom validation.

Required Fields
A field is considered to be required if any of the following conditions are met:

  • The field has the "required" attribute
  • The field name begins with "req_"
  • The field has the data-validation attribute and "required" is one of the rules listed.

Email Addresses
Field values are checked to be valid email addresses if:

  • The input type is "email"
  • The field name is "email"

Full Names
If a field has the data-validation attribute and "fullname" is one of the rules listed, daformcheck will check that it contains at least two words.

Validation Rules

The data-validation attribute should contain a list of rules, separated by the pipe character e.g.

<input type="text" data-validation="required|fullname" />

Extending daformcheck

This example shows how to extend daformcheck to perform additional validation via an external API.


formCheck.checks.isValidEmailData8 = function($formfield) {
        
    if((($formfield.attr('type') == 'email') || ($formfield.attr('name') == 'email')) && $formfield.val() != '') {
            
        $.ajax('/ajaxvalidateemail', {
            data: {
                token: getToken(),
                email: $formfield.val()
            },
            dataType: 'json' ,
            method: 'POST',
            success: function(response) {
                if(response.valid) {
                    formCheck.doneCheck();
                } else {
                    $formfield.validate('error', 'Invalid email'); 
                }
            },
            error: function() {
                formCheck.doneCheck();
            }
        });   
    } else {
        formCheck.doneCheck();
    }
        
};

Contact Us

Address: 22a Fishergate York, YO10 4AB · Tel: 01904 636677 · Email: info@dotadmin.com