A while ago I uploaded a demo (enhancements of the jQuery on-screen keyboard). Since I have added support for HTML5 form validation. In the write function it basically checks the inputs for HTML5 validation rules to determine output write. This is the gist of it:

See Keyboard Demo See Keyboard Demo

write: function(m) {

    var $el = jsKeyboard.currentElement,
        val = $el.val(),
        charStr = String.fromCharCode(m),
        pos = jsKeyboard.currentElementCursorPosition,
        output = [val.slice(0, pos), charStr, val.slice(pos)].join(''),
        doWrite = true;

    //max length - html5: maxlength="x"
    if ($el.attr('maxlength'))
        doWrite = (output.length <= $el.attr('maxlength'));

    //allow numbers only - html5: number attribute
    if (doWrite && $el.hasAttr('datatype'))
        if ($el.attr('number'))
            doWrite = !isNaN(charStr);

    //more HTML5 validation rules here...


    //if passed validation do it.
    if (doWrite)
        jsKeyboard.currentElementCursorPosition++; //+1 cursor

Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

Special Offer
Free course!

Git into it! Bonus course Introduction to Git is yours when you take up a free 14 day SitePoint Premium trial.