Validanguage 0.9: More form validation
Date : 2008 06 12 Category : Tech & DevelopmentForm validation may seem a little boring, but it is still one of the low hanging fruits for Ajax.
Validanguage is a simple new validation framework that you can access and configure through HTML (via comments rather than attributes) and a JSON API.
For example, if you place the following next to an input, it will flash red if you try to type in anything other than a number, a dollar, or a period (good for a price).
PLAIN TEXT HTML:<!-- <validanguage target="example" mode="allow" expression="numeric$." /> -->
Or you can configure it via JSON:
PLAIN TEXT JAVASCRIPT:validanguage.el.example = { characters: { mode: 'allow', expression: 'numeric$.', onsubmit: true, errorMsg: 'You may only enter numbers, periods, or the dollar sign.' }, required: true, errorMsg: 'Please enter a valid monetary amount', onsuccess: 'someObject.successHandler', onerror: [errorHandler1, errorHandler2] }
Features
100% unobtrusive javascript, name-spaced under the global validanguage object. No inline event handlers required (not even to block form submissions) No external libraries required (optional Prototype integration) Use inheritance to manage your validation settings. Define a setting globally, per-form, or per-element. Supports a choice of two APIs: HTML-like API placed inside comment tags. The choice for ease of use and simplicity. JSON-based API. For advanced configuration. Easily configure custom validation functions to be triggered onblur, onsubmit, onchange, etc. Add onsuccess and onerror callback functions to integrate Validanguage into your existing site design. All validation functions and onsuccess/onerror callbacks are scoped so that the this keyword refers to the validated element.A normalized "text" argument is supplied to validation functions for textareas and textboxes.
The inherited error message is automatically supplied to the onerror callback(s) as the first argument. Easy-to-use keypress suppression.