fValidate.core

fValidate.core - /

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: / *********************************************************************************** **************** * *-- Form validation script by Peter Bailey, Copyright (c) 2001-2003 * Version 5.01b * Updated on Feb 07, 2004 * www.peterbailey.net * [email protected] * * IF YOU USE THIS SCRIPT, GIVE ME CREDIT PLEASE =) * * Visit http://www.peterbailey.net/fValidate/ for more info * * Feel free to contact me with any questions, comments, problems, or suggestions * * Note: This document most easily read with tab spacing set to 4 * *********************************************************************************** ********************/ * /* Create static fvalidate object------------------------------------------- */ if ( typeof fvalidate == 'undefined' ) { var fvalidate = new Object(); } /* Generic event handling------------------------------------------- */ fvalidate.addEvent = function( obj, evt, fn, useCapture ) { if ( typeof obj.attachEvent != 'undefined' ) { obj.attachEvent( "on" + evt, fn ); } else if ( typeof obj.attachEventListener != 'undefined' ) { obj.addEventListener( evt, fn, Boolean( useCapture ) ); } } fvalidate.addEvents = function( obj, evts, fn, useCapture ) { var i = 0, evt; while( evt = evts[i++] ) { this.addEvent( obj, evt, fn, Boolean( useCapture ) ); } } /* Main validation routine------------------------------------------- */ function validateForm( f, bConfirm, bDisable, bDisableR, groupError, errorMode ) { // Set defaults bConfirm = Boolean( bConfirm ); bDisable = Boolean( bDisable ); bDisableR = Boolean( bDisableR ); groupError = Boolean( groupError ); errorMode = ( typeof errorMode != 'undefined' ) ? parseInt( errorMode, 10 ) : 0; : // Init vars and fValidate object var params, fvCode, type; if ( typeof f.fv == 'undefined' ) { f.fv = new fValidate( f, errorMode, groupError ); } else { } f.fv._reset(); f.fv.errorMode = errorMode; } // Loop through all form elements L var elem, i = 0, attr = f.fv.config.code; while ( elem = f.elements[i++] ) { // Skip fieldsets if ( elem.nodeName == "FIELDSET" ) continue; i // Does element have validator attribute? (short-circuit check) fvCode = ( elem[attr] ) ? elem[attr] : elem.getAttribute( attr ); if ( !( typeof fvCode == 'undefined' || fvCode == null || fvCode == "" ) ) { // Set params, validation type, and validation state params = fvCode.split( "|" ); type = params[0]; elem.validated = true; = // Valid validator type? if ( typeof f.fv[type] == 'undefined' ) { f.fv.devError( [type, elem.name], 'notFound' ); return false; } // Check for modifiers switch( params.last() ) { case 'bok' : // bok requested params = params.reduce( 1, 1 ); elem.bok = true; break; case 'if' : // Conditional validation requested params = params.reduce( 1, 1 ); elem._if_ = true; break; case 'then' : // Conditional validation requested params = params.reduce( 1, 1 ); elem._then_ = true; break; default : // No modifiers params = params.reduce( 1, 0 ); p } // Is element an array?...
View Full Document

This note was uploaded on 08/14/2009 for the course ITP 204X taught by Professor Dent during the Spring '08 term at USC.

Page1 / 16

fValidate.core - /

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online