Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / JSResources / Validation.resx
blob2b28ff597ecc9d21ccc144cf1c27fa0845aded88
1 <?xml version="1.0" encoding="utf-8"?>
2 <root>
3 <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
4 <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
5 <xsd:element name="root" msdata:IsDataSet="true">
6 <xsd:complexType>
7 <xsd:choice maxOccurs="unbounded">
8 <xsd:element name="metadata">
9 <xsd:complexType>
10 <xsd:sequence>
11 <xsd:element name="value" type="xsd:string" minOccurs="0" />
12 </xsd:sequence>
13 <xsd:attribute name="name" use="required" type="xsd:string" />
14 <xsd:attribute name="type" type="xsd:string" />
15 <xsd:attribute name="mimetype" type="xsd:string" />
16 <xsd:attribute ref="xml:space" />
17 </xsd:complexType>
18 </xsd:element>
19 <xsd:element name="assembly">
20 <xsd:complexType>
21 <xsd:attribute name="alias" type="xsd:string" />
22 <xsd:attribute name="name" type="xsd:string" />
23 </xsd:complexType>
24 </xsd:element>
25 <xsd:element name="data">
26 <xsd:complexType>
27 <xsd:sequence>
28 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
29 <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
30 </xsd:sequence>
31 <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
32 <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
33 <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
34 <xsd:attribute ref="xml:space" />
35 </xsd:complexType>
36 </xsd:element>
37 <xsd:element name="resheader">
38 <xsd:complexType>
39 <xsd:sequence>
40 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
41 </xsd:sequence>
42 <xsd:attribute name="name" type="xsd:string" use="required" />
43 </xsd:complexType>
44 </xsd:element>
45 </xsd:choice>
46 </xsd:complexType>
47 </xsd:element>
48 </xsd:schema>
49 <resheader name="resmimetype">
50 <value>text/microsoft-resx</value>
51 </resheader>
52 <resheader name="version">
53 <value>2.0</value>
54 </resheader>
55 <resheader name="reader">
56 <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
57 </resheader>
58 <resheader name="writer">
59 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
60 </resheader>
61 <data name="fValidateConfig" xml:space="preserve">
62 <value><![CDATA[
63 function fValConfig()
65 /* Globals. Modify these to suit your setup
66 ------------------------------------------- */
68 // Attribute used for fValidate Validator codes
69 this.code = 'validators';
71 // Attribute used for custom error messages (override built-in error messages)
72 this.emsg = 'emsg';
74 // Attribute used for pattern with custom validator type
75 this.pattern = 'pattern';
77 // Change this to the classname you want for the error highlighting
78 this.errorClass = 'errHilite';
80 // If you wish fValidate to use only single classNames for errors
81 this.useSingleClassNames = false; // or true
83 // This is the even that triggers the clearing of the errorClass hilighting
84 this.clearEvent = 'change'; // 'change' | 'blur' | null
86 // For browsers that don't support attachEvent or addEventListere - override existing events for error reverting?
87 this.eventOverride = false;
89 // If the bConfirm flag is set to true, the users will be prompted with CONFIRM box with this message
90 // See your language file for this value
91 this.confirmMsg = fvalidate.i18n.config.confirmMsg;
93 // If user cancels CONFIRM, then this message will be alerted. If you don't want this alert to show, then
94 // empty the variable ( this.confirmAbortMsg = ''; )
95 // See your langauge file for this value
96 this.confirmAbortMsg = fvalidate.i18n.config.confirmAbortMsg;
98 // Enter the name/id of your form's submit button here. Can be a string or array of strings
99 this.submitButton = ['Submit','Submit2'];
101 // Enter the name/id of your form's reset button here
102 this.resetButton = 'Reset';
104 // Ender the name or id of the SELECT object here. Make sure you pay attention to the values (CC Types)
105 // used in the case statement for the function validateCC()
106 this.ccType = 'Credit_Card_Type';
108 // NOTE: The config value below exists for backwards compatibility with fValidate 3.55b. If you have a newer
109 // version, use the above this.ccType instead.
110 // Enter the DOM name of the SELECT object here. Make sure you pay attention to the values (CC Types)
111 // used in the case statement for the function validateCC()
112 this.ccTypeObj = 'form1.Credit_Card_Type';
114 // Element where box errors will appear
115 this.boxError = 'errors';
117 // Added by Ivan to allow for a heading in the box error mode
118 this.boxErrorHeadingClass = 'errorsHeading';
120 // Prefix given to all error paragraphs in box error mode
121 this.boxErrorPrefix = 'fv_error_';
123 this.displayName= 'displayName';
126 // Added by Ivan to designate a label to be an error label
127 this.errorSelectorCssClass = 'error';
129 ]]></value>
130 </data>
131 <data name="fValidateCore" xml:space="preserve">
132 <value><![CDATA[
134 /***************************************************************************************************
136 *-- Form validation script by Peter Bailey, Copyright (c) 2001-2003
137 * Version 5.01b
138 * Updated on Feb 07, 2004
139 * www.peterbailey.net
140 * me@peterbailey.net
142 * IF YOU USE THIS SCRIPT, GIVE ME CREDIT PLEASE =)
144 * Visit http://www.peterbailey.net/fValidate/ for more info
146 * Feel free to contact me with any questions, comments, problems, or suggestions
148 * Note: This document most easily read with tab spacing set to 4
150 *******************************************************************************************************/
152 /* Create static fvalidate object
153 ------------------------------------------- */
154 if ( typeof fvalidate == 'undefined' )
156 var fvalidate = new Object();
159 /* Generic event handling
160 ------------------------------------------- */
161 fvalidate.addEvent = function( obj, evt, fn, useCapture )
163 if ( typeof obj.attachEvent != 'undefined' )
165 obj.attachEvent( "on" + evt, fn );
167 else if ( typeof obj.attachEventListener != 'undefined' )
169 obj.addEventListener( evt, fn, Boolean( useCapture ) );
172 fvalidate.addEvents = function( obj, evts, fn, useCapture )
174 var i = 0, evt;
175 while( evt = evts[i++] )
177 this.addEvent( obj, evt, fn, Boolean( useCapture ) );
181 /* Main validation routine
182 ------------------------------------------- */
183 function validateForm( f, bConfirm, bDisable, bDisableR, groupError, errorMode )
185 // Set defaults
186 bConfirm = Boolean( bConfirm );
187 bDisable = Boolean( bDisable );
188 bDisableR = Boolean( bDisableR );
189 groupError = Boolean( groupError );
190 errorMode = ( typeof errorMode != 'undefined' ) ? parseInt( errorMode, 10 ) : 0;
192 // Init vars and fValidate object
193 var params, fvCode, type;
194 if ( typeof f.fv == 'undefined' )
196 f.fv = new fValidate( f, errorMode, groupError );
197 } else {
198 f.fv._reset();
199 f.fv.errorMode = errorMode;
202 // Loop through all form elements
203 var elem, i = 0, attr = f.fv.config.code;
204 while ( elem = f.elements[i++] )
206 // Skip fieldsets
207 if ( elem.nodeName == "FIELDSET" ) continue;
209 // Does element have validator attribute? (short-circuit check)
210 fvCode = ( elem[attr] ) ? elem[attr] : elem.getAttribute( attr );
211 if ( !( typeof fvCode == 'undefined' || fvCode == null || fvCode == "" ) )
213 // Set params, validation type, and validation state
214 params = fvCode.split( "|" );
215 type = params[0];
216 elem.validated = true;
218 // Valid validator type?
219 if ( typeof f.fv[type] == 'undefined' )
221 f.fv.devError( [type, elem.name], 'notFound' );
222 return false;
225 // Check for modifiers
226 switch( params.last() )
228 case 'bok' : // bok requested
229 params = params.slicex( 1, 1 );
230 elem.bok = true;
231 break;
232 case 'if' : // Conditional validation requested
233 params = params.slicex( 1, 1 );
234 elem._if_ = true;
235 break;
236 case 'then' : // Conditional validation requested
237 params = params.slicex( 1, 1 );
238 elem._then_ = true;
239 break;
240 default : // No modifiers
241 params = params.slicex( 1, 0 );
245 // Is element an array?
246 if ( /radio|checkbox/.test( elem.type ) )
248 // Set group property
249 elem.group = f.elements[elem.name];
252 // Add events if not already added
253 if ( typeof elem.fName == 'undefined' )
255 // If element is an array
256 if ( typeof elem.group != 'undefined' )
258 for ( var j = 0; j < elem.group.length; j++ )
260 // Apply event-function to each child
261 if ( f.fv.config.clearEvent != null )
263 // fvalidate.addEvent( elem.group.item( j ), fv.config.clearEvent, fv.revertError, false );
264 addEvent( elem.group.item( j ), f.fv.config.clearEvent, f.fv, 'revertError', false );
268 else
270 // Apply event-function to element
271 // fvalidate.addEvent( elem, fv.config.clearEvent, fv.revertError, false );
272 addEvent( elem, f.fv.config.clearEvent, f.fv, 'revertError', false );
276 // Set formatted name, current element
277 if ( elem.attributes[f.fv.config.displayName] != null)
279 elem.fName = elem.attributes[f.fv.config.displayName].value.format();
281 else
283 elem.fName = elem.name.format();
286 f.fv.elem = elem;
287 f.fv.type = type;
289 // Create function to call the proper validator method of the fValidate class
290 var func = new Function( "obj", "method", "obj[method]( " + params.toArgString() + " );" );
291 func( f.fv, type );
293 // If element test failed AND group error is off, return false
294 if ( elem.validated == false && groupError == false ) return false;
296 // Clear error if field okay
297 if ( elem.validated == true ) f.fv.revertError();
299 } // end of element loop
301 // If group error, show it
302 if ( groupError ) f.fv.showGroupError();
304 // Return false if errors found
305 if ( f.fv.errors.length > 0 ) return false;
307 // Show pre-submission confirmation
308 if ( bConfirm && !confirm( f.fv.config.confirmMsg ) )
310 if ( f.fv.config.confirmAbortMsg != '' ) alert( f.fv.config.confirmAbortMsg );
311 return false;
314 // Disable reset and/or submit buttons if requested
315 if ( bDisable )
317 if ( typeof f.fv.config.submitButton == 'object' )
319 var sb, j = 0;
320 while( sb = f.fv.config.submitButton[j++] )
322 if ( f.fv.elementExists( sb ) )
324 f.elements[sb].disabled = true;
328 else if ( f.fv.elementExists( f.fv.config.submitButton ) )
330 f.elements[f.fv.config.submitButton].disabled = true;
333 if ( bDisableR && f.fv.elementExists( f.fv.config.resetButton ) )
335 f.elements[f.fv.config.resetButton].disabled = true;
338 // Successful Validation. Submit form
339 return true;
341 function addEvent( elem, evt, obj, method, capture )
343 var self = elem;
344 if ( typeof elem.attachEvent != 'undefined' )
346 elem.attachEvent( "on" + evt, function() { obj[method]( self ) } );
348 else if ( typeof elem.addEventListener != 'undefined' )
350 elem.addEventListener( evt, function() { obj[method]( self ) }, capture );
352 else if ( f.fv.config.eventOverride )
354 eleme['on' + evt] = function() { obj[method]( self ) };
359 /* Constructor
360 ------------------------------------------- */
361 function fValidate( f, errorMode, groupError )
363 var self = this;
364 this.form = f;
365 this.errorMode = errorMode;
366 this.groupError = groupError;
367 this.errors = new Array();
368 this.validated = true;
369 this.config = new fValConfig();
370 this.i18n = fvalidate.i18n;
371 var selectorClass = this.config.errorSelectorCssClass;
372 // Add reset action to clear visual error cues
373 f.onreset = function()
375 var elem, i = 0;
376 while ( elem = this.elements[i++] )
378 self.revertError( elem );
382 addLabelProperties();
384 // Parses form and adds label properties to elements that have one specified
385 function addLabelProperties()
387 // Collect all label elements in form, init vars
388 if ( typeof f.getElementsByTagName == 'undefined' ) return;
389 var labels = f.getElementsByTagName( "label" );
390 var label, i = j = 0;
391 var elem;
392 // Loop through labels retrieved
393 while ( label = labels[i++] )
395 // For Opera 6
396 if ( typeof label.htmlFor == 'undefined' ) return;
398 // Skip the current element if the label is not for anything
399 if ( label.htmlFor == '') break;
401 // Retrieve element
402 elem = f.elements[label.htmlFor];
403 if ( typeof elem == 'undefined' )
404 { // No element found for label
405 self.devError( [label.htmlFor], 'noLabel' );
407 else if ( typeof elem.label != 'undefined' )
408 { // label property already added
409 continue;
411 else if ( typeof elem.length != 'undefined' && elem.length > 1 && elem.nodeName != 'SELECT' )
412 { // For arrayed elements
413 for ( j = 0; j < elem.length; j++ )
415 elem.item( j ).label = label;
419 if(label.className.indexOf(selectorClass) > -1)
420 // Regular label
421 elem.label = label;
426 /* Reset for another validation
427 ------------------------------------------- */
428 fValidate.prototype._reset = function()
430 this.errors = new Array();
431 this.showErrors = new Array();
434 /* Checks if element exists in form
435 ------------------------------------------- */
436 fValidate.prototype.elementExists = function( elemName )
438 return Boolean( typeof this.form.elements[elemName] != 'undefined' );
441 /* Receives error message and determines action
442 ------------------------------------------- */
443 fValidate.prototype.throwError = function( args, which )
445 var elem = this.elem;
447 // Arrayed element?
448 if ( typeof elem.name == 'undefined' )
450 elem = elem[0];
453 // Bok requested AND element blank OR conditional validation?
454 if ( elem.bok && this.isBlank() )
455 { // skip
456 elem.validated = true;
457 return;
460 // Part of a conditional validation?
461 if ( elem.cv )
463 return;
466 // Set failsafe to false
467 elem.validated = false;
469 // Create error message
470 which = this.setArg( which, 0 );
471 args = this.setArg( args, [] );
472 emsgElem = ( typeof this.elem.getAttribute == "undefined" ) ?
473 this.elem[0]:
474 this.elem;
475 if ( emsgElem.getAttribute( this.config.emsg ) )
477 var error = emsgElem.getAttribute( this.config.emsg );
479 var error = this.translateMessage( args, this.i18n.errors[this.type][which] );
481 // Group error mode?
482 if ( this.groupError )
484 // Push error onto stack
485 this.errors.push( {'elem':elem, 'msg': error} );
487 else
489 // Process error message
490 this.showError( error, false, emsgElem );
492 var focusElem = ( typeof elem.fields != 'undefined' )?
493 elem.fields[0]:
494 elem;
496 // Focus and select elements, if possible
497 this.selectFocus( focusElem );
502 /* Shows error message to user
503 ------------------------------------------- */
504 fValidate.prototype.showError = function( emsg, last, elem )
506 // Set variables
507 var self = this,
508 elem = this.setArg( elem, this.elem ),
509 isHidden = Boolean( elem.type == 'hidden' ),
510 label = ( isHidden ) ? null : elem.label || null,
511 emsg = ( elem.getAttribute( this.config.emsg ) ) ? elem.getAttribute( this.config.emsg ).replace( /\\n/g, "\n" ) : emsg,
512 errorClass = this.config.errorClass,
513 singleCSS = this.config.useSingleClassNames,
514 selectorClass = this.config.errorSelectorCssClass;
516 if ( typeof this.showErrors == 'undefined' ) this.showErrors = new Array();
518 // Determine which error modes to use
519 switch( this.errorMode )
520 { // This represents all possible combinations
521 case 0 : alertError(); break;
522 case 1 : inputError(); break;
523 case 2 : labelError(); break;
524 case 3 : appendError(); break;
525 case 4 : boxError(); break;
526 case 5 : inputError(); labelError(); break;
527 case 6 : inputError(); appendError(); break;
528 case 7 : inputError(); boxError(); break;
529 case 8 : inputError(); alertError(); break;
530 case 9 : labelError(); appendError(); break;
531 case 10 : labelError(); boxError(); break;
532 case 11 : labelError(); alertError(); break;
533 case 12 : appendError(); boxError(); break;
534 case 13 : appendError(); alertError(); break;
535 case 14 : boxError(); alertError(); break;
536 case 15 : inputError(); labelError(); appendError(); break;
537 case 16 : inputError(); labelError(); boxError(); break;
538 case 17 : inputError(); labelError(); alertError(); break;
539 case 18 : inputError(); appendError(); boxError(); break;
540 case 19 : inputError(); appendError(); alertError(); break;
541 case 20 : inputError(); boxError(); alertError(); break;
542 case 21 : labelError(); appendError(); boxError(); break;
543 case 22 : labelError(); appendError(); alertError(); break;
544 case 23 : appendError(); boxError(); alertError(); break;
545 case 24 : inputError(); labelError(); appendError(); boxError(); break;
546 case 25 : inputError(); labelError(); appendError(); alertError(); break;
547 case 26 : inputError(); appendError(); boxError(); alertError(); break;
548 case 27 : labelError(); appendError(); boxError(); alertError(); break;
549 case 28 : inputError(); labelError(); appendError(); boxError(); alertError(); break;
551 // Regular alert error
552 function alertError()
554 if ( self.groupError ) self.showErrors.push( emsg );
555 else alert( emsg );
556 if ( last ) alert( self.i18n.groupAlert + self.showErrors.join( "\n\n- " ) );
558 // Applies class to form element
559 function inputError()
561 if ( ( typeof elem.length != 'undefined' && elem.length > 1 && elem.nodeName != 'SELECT' ) || isHidden )
563 var subelem, i = 0;
564 while( subelem = ( isHidden ) ? elem.fields[i++] : elem.item( i++ ) )
566 if ( subelem.className != '' && singleCSS )
568 subelem.revertClass = subelem.className;
569 subelem.className = errorClass;
570 } else {
571 self.addCSSClass( subelem, errorClass );
575 else
577 if ( singleCSS )
579 elem.revertClass = elem.className;
580 elem.className = errorClass;
581 } else {
582 self.addCSSClass( elem, errorClass );
586 // Applies class to element's label
587 function labelError()
589 if ( label == null ) return;
590 if ( self.config.useSingleClassNames )
592 label.className = errorClass;
593 } else {
594 self.addCSSClass( label, errorClass );
598 // Appends error message to element's label
599 function appendError()
601 if ( label == null || label.className.indexOf(selectorClass) == -1 ) return;
602 if ( typeof label.original == 'undefined' )
603 label.original = label.innerHTML;
604 label.innerHTML = label.original + emsg.toHTML();
606 // Appends Error message to pre-defined element
607 function boxError()
609 if ( typeof self.boxError == 'undefined' ) self.boxError = document.getElementById( self.config.boxError );
610 if ( self.boxError == null )
612 self.devError( [self.config.boxError], 'noBox' );
613 return;
615 if ( typeof self.elem.name == 'undefined' || self.elem.name == "" )
617 self.devError( [self.elem[self.config.code]], 'missingName' );
618 return;
620 var errorId = self.config.boxErrorPrefix + self.elem.name,
621 errorElem;
622 if ( errorElem = document.getElementById( errorId ) ) // short-circuit
624 errorElem.firstChild.innerHTML = emsg.toHTML();
626 else
628 errorElem = document.createHTMLElement( 'li', { id: errorId, 'innerHTML': emsg.toHTML(), title: self.i18n.boxToolTip } );
629 self.boxError.appendChild( errorElem );
630 errorElem.onclick = function()
632 var elem = self.form.elements[this.id.replace( self.config.boxErrorPrefix, "" )];
633 if ( typeof elem.fields != 'undefined' ) elem = elem.fields[0];
634 if ( typeof elem.select != 'undefined' ) elem.select();
635 if ( typeof elem.focus != 'undefined' ) elem.focus();
638 self.boxError.style.display = "block";
642 /* Handles element className manipulation
643 ------------------------------------------- */
644 fValidate.prototype.removeCSSClass = function( elem, className )
646 elem.className = elem.className.replace( className, "" ).trim();
648 fValidate.prototype.addCSSClass = function( elem, className )
650 this.removeCSSClass( elem, className );
651 elem.className = ( elem.className + " " + className ).trim();
654 /* Processes errors in stack for group error mode
655 ------------------------------------------- */
656 fValidate.prototype.showGroupError = function()
658 for ( var error, firstElem, i = 0; ( error = this.errors[i] ); i++ )
660 if ( i == 0 ) firstElem = error.elem;
661 this.elem = error.elem;
662 this.showError( error.msg, Boolean( i == ( this.errors.length - 1 ) ) );
664 if(firstElem){
665 var focusElem = ( typeof firstElem.fields != 'undefined' )?
666 firstElem.fields[0]:
667 firstElem;
668 this.selectFocus( focusElem );
672 /* Reverts any visible error notification upon event
673 ------------------------------------------- */
674 fValidate.prototype.revertError = function( elem )
676 elem = this.setArg( elem, this.elem );
677 var isHidden = Boolean( elem.type == 'hidden' ),
678 errorClass = this.config.errorClass,
679 i = 0,
680 errorElem,
681 subelem,
682 headingClass = this.config.boxErrorHeadingClass;
684 if ( ( typeof elem.length != 'undefined' && elem.length > 1 && elem.nodeName != 'SELECT' ) || isHidden )
686 if ( isHidden && typeof elem.fields != 'undefined' )
688 while( subelem = ( isHidden ) ? elem.fields[i++] : elem.item( i++ ) )
690 if ( typeof subelem.revertClass != 'undefined' )
692 subelem.className = subelem.revertClass;
696 } else {
697 if ( this.config.useSingleClassNames )
699 if ( typeof subElement.revertClass != 'undefined' )
701 elem.className = elem.revertClass;
703 } else {
704 this.removeCSSClass( elem, errorClass );
707 if ( typeof elem.label != 'undefined' )
709 if ( this.config.useSingleClassNames )
711 elem.label.className = '';
712 } else {
713 this.removeCSSClass( elem.label, errorClass );
715 elem.label.innerHTML = ( elem.label.original || elem.label.innerHTML );
717 if ( typeof this.boxError != 'undefined' )
719 if ( typeof this.boxError.normalize != 'undefined' ) this.boxError.normalize();
720 if ( errorElem = document.getElementById( this.config.boxErrorPrefix + elem.name ) )
722 this.boxError.removeChild( errorElem );
724 // Added by Ivan allow for a heading node to be in the error box.
725 var nodeCount = 0;
726 if(this.boxError.tagName.toUpperCase() == 'UL'){
727 for(var i=0;i<this.boxError.childNodes.length;i++){
729 var node = this.boxError.childNodes[i];
730 if(node.tagName && node.tagName == 'LI' && node.className != headingClass) nodeCount++;
732 if ( nodeCount == 0 ) this.boxError.style.display = 'none';
737 /* Focus and select elements, if possible
738 ------------------------------------------- */
739 fValidate.prototype.selectFocus = function( elem )
741 if ( typeof elem.select != 'undefined' ) elem.select();
742 if ( typeof elem.focus != 'undefined' ) elem.focus();
745 /* Developer assistance method - shows error if validator/element-type mismatch
746 ------------------------------------------- */
747 fValidate.prototype.typeMismatch = function()
749 var pats = {
750 'text': 'text|password|textarea',
751 'ta': 'textarea',
752 'hidden': 'hidden',
753 's1': 'select-one',
754 'sm': 'select-multiple',
755 'select': 'select-one|select-multiple',
756 'rg': 'radio',
757 'radio': 'radio',
758 'cb': 'checkbox',
759 'file': 'file'
761 var fail = false,
762 expected = new Array(),
763 result = key = type = regex = "";
764 for ( var i = 0; i < arguments.length; i++ )
766 type = pats[arguments[i]];
767 regex = new RegExp( type );
768 result += ( regex.test( this.elem.type ) ) ? "1" : "0";
769 key += "0";
770 expected.push( type );
772 if ( key ^ result == 0 )
774 this.devError( [this.elem.fName, this.elem.type, expected.join( "|" ).replace( /\|/g, this.i18n.or )], 'mismatch' );
775 this.elem.validated = false;
776 return true;
778 return false;
781 /* Returns value(s) of reference element passed
782 ------------------------------------------- */
783 fValidate.prototype.getValue = function( elem )
785 switch ( elem.type )
787 case 'text' :
788 case 'password' :
789 case 'textarea' :
790 case 'hidden' :
791 case 'file' :
792 return elem.value;
793 case 'radio':
794 case 'select-single':
795 if ( typeof elem.length == 'undefined' )
797 return elem.value;
798 } else {
799 for ( var i = 0; i < elem.length; i++ )
801 choice = ( elem.type == 'radio' ) ? "checked" : "selected";
802 if ( elem[i][choice] )
804 return elem[i].value;
808 case 'select-multiple' :
809 case 'checkbox' :
810 if ( typeof elem.length == 'undefined' )
812 return elem.value
813 } else {
814 var returnValues = new Array();
815 for ( var i = 0; i < elem.length; i++ )
817 choice = ( elem.type == 'checkbox' ) ? "checked" : "selected";
818 if ( elem[i][choice] )
820 returnValues.push( elem[i].value );
823 return returnValues;
825 default: return null;
829 /* Generic argument setting method
830 ------------------------------------------- */
831 fValidate.prototype.setArg = function( arg, def )
833 return ( typeof arg == 'undefined' || arg == '' || arg == null ) ? def : arg;
836 /* Blank checker. Optional string argument for evaluating element other than current
837 ------------------------------------------- */
838 fValidate.prototype.isBlank = function( el )
840 var elem = this.form.elements[el] || this.elem;
841 return Boolean( /^\s*$/.test( elem.value ) );
844 /* Translates messages using language file
845 ------------------------------------------- */
846 fValidate.prototype.translateMessage = function( args, format )
848 var msg = ""
849 for ( var i = 0; i < format.length; i++ )
851 msg += ( typeof format[i] == 'number' ) ? args[format[i]] : format[i];
853 return msg;
856 /* Throws developer errors
857 ------------------------------------------- */
858 fValidate.prototype.devError = function( args, which )
860 if ( typeof args == 'string' )
862 which = args;
863 args = [];
865 which = this.setArg( which, this.type );
866 var format = this.i18n.devErrors[which];
867 var a = [
868 this.i18n.devErrors.lines[0],
869 '----------------------------------------------------------------------------------------------',
870 this.translateMessage( args, format ),
871 '----------------------------------------------------------------------------------------------',
872 this.i18n.devErrors.lines[1]
874 alert( a.join( "\n" ) );
877 /* Throws specific developer error
878 ------------------------------------------- */
879 fValidate.prototype.paramError = function( param, elemName )
881 elemName = this.setArg( elemName, this.elem.name );
882 this.devError( [param, this.type, elemName], 'paramError' );
884 /* Non-fValidate methods *****************************************/
886 /* For easy creation of DOM nodes
887 ------------------------------------------- */
888 document.createHTMLElement = function( elemName, attribs )
890 if ( typeof document.createElement == 'undefined' ) return;
891 var elem = document.createElement( elemName );
892 if ( typeof attribs != 'undefined' )
894 for ( var i in attribs )
896 switch ( true )
898 case ( i == 'text' ) : elem.appendChild( document.createTextNode( attribs[i] ) ); break;
899 case ( i == 'class' ) : elem.className = attribs[i]; break;
900 default : elem.setAttribute( i, '' ); elem[i] = attribs[i];
904 return elem;
907 /* Trims b items from the beginning of the array, e items from the end
908 ------------------------------------------- */
909 Array.prototype.slicex = function( b, e )
911 var a = new Array();
912 var count = 0;
913 for ( var i = b; i < this.length - e; i++ )
915 a[count++] = this[i];
917 return a;
920 /* Returns array as argument-compatible string
921 ------------------------------------------- */
922 Array.prototype.toArgString = function()
924 var a = new Array();
925 for ( var i = 0; i < this.length; i++ )
927 a.push( "'" + this[i] + "'" );
929 return a.toString();
932 /* Prototype push if missing
933 ------------------------------------------- */
934 if ( typeof Array.prototype.push == 'undefined' )
936 Array.prototype.push = function()
938 for ( var i = 0; i < arguments.length; i++ )
940 this[this.length] = arguments[i];
945 /* Returns last item of the array
946 ------------------------------------------- */
947 Array.prototype.last = function()
949 return this[this.length-1];
952 /* Removes the follow charaters _[] from an elements name for human-reading
953 ------------------------------------------- */
954 String.prototype.format = function()
956 return this.replace( /\_/g, " ").replace( /\[|\]/g, "" );
959 /* Replaces newline characters with XHTML BR tags
960 ------------------------------------------- */
961 String.prototype.toHTML = function()
963 return this.replace( /\n/g, "<br />" ).replace( /\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;" );
966 /* Trims leading and trailing whitespace from string
967 ------------------------------------------- */
968 String.prototype.trim = function()
970 return this.replace( /^\s+|\s+$/, "" );
973 /* Escapes necessary charactes for string-generated regular expressions
974 ------------------------------------------- */
975 String.prototype.toPattern = function()
977 return this.replace( /([\.\*\+\{\}\(\)\<\>\^\$\\])/g, "\\$1" );
981 ]]></value>
982 </data>
983 <data name="fValidateValidators" xml:space="preserve">
984 <value><![CDATA[
985 /*< blank basic *******************************************************************/
986 fValidate.prototype.blank = function()
988 if ( this.typeMismatch( 'text' ) ) return;
989 if ( this.isBlank() )
991 this.throwError( [this.elem.fName] );
994 /*/>*/
995 /*< number numbers *******************************************************************/
996 fValidate.prototype.number = function( type, lb, ub )
998 if ( this.typeMismatch( 'text' ) ) return;
999 var num = ( type == 0 ) ? parseInt( this.elem.value, 10 ) : parseFloat( this.elem.value );
1000 lb = this.setArg( lb, 0 );
1001 ub = this.setArg( ub, Number.infinity );
1002 if ( lb > ub )
1004 this.devError( [lb, ub, this.elem.name] );
1005 return;
1007 var fail = Boolean( isNaN( num ) || num != this.elem.value );
1008 if ( !fail )
1010 switch( true )
1012 case ( lb != false && ub != false ) : fail = !Boolean( lb <= num && num <= ub ); break;
1013 case ( lb != false ) : fail = Boolean( num < lb ); break;
1014 case ( ub != false ) : fail = Boolean( num > ub ); break;
1017 if ( fail )
1019 this.throwError( [this.elem.fName] );
1020 return;
1022 this.elemPass = true;
1024 /*/>*/
1025 /*< numeric numbers *******************************************************************/
1026 fValidate.prototype.numeric = function( len )
1028 if ( this.typeMismatch( 'text' ) ) return;
1029 len = this.setArg( len, '*' );
1030 var regex = new RegExp( ( len == '*' ) ? "^\\d+$" : "^\\d{" + parseInt( len, 10 ) + "}\\d*$" );
1031 if ( !regex.test( this.elem.value ) )
1033 if ( len == "*" )
1035 this.throwError( [this.elem.fName] );
1036 } else {
1037 this.throwError( [len, this.elem.fName], 1 );
1041 /*/>*/
1042 /*< length basic *******************************************************************/
1043 fValidate.prototype.length = function( len, maxLen )
1045 if ( this.typeMismatch( 'text' ) ) return;
1046 var vlen = this.elem.value.length;
1047 len = Math.abs( len );
1048 maxLen = Math.abs( this.setArg( maxLen, Number.infinity ) );
1049 if ( len > maxLen )
1051 this.devError( [len, maxLen, this.elem.name] );
1052 return;
1054 if ( len > parseInt( vlen, 10 ) )
1056 this.throwError( [this.elem.fName, len] );
1058 if ( vlen > maxLen )
1060 this.throwError( [this.elem.fName, maxLen, vlen], 1 );
1063 /*/>*/
1064 /*< alnum extended *******************************************************************/
1065 fValidate.prototype.alnum = function( minLen, tCase, numbers, spaces, puncs )
1067 if ( this.typeMismatch( 'text' ) ) return;
1069 tCase = this.setArg( tCase, "a" );
1071 //alert( [minLen,tCase,numbers,spaces,puncs] );
1073 numbers = ( numbers == "true" || numbers == "1" );
1074 spaces = ( spaces == "true" || spaces == "1" );
1076 //alert( [minLen,tCase,numbers,spaces,puncs] );
1078 var okChars = "",
1079 arrE = ['None','Any','No','No','Any'];
1081 if ( minLen != '*' )
1083 minLen = parseInt( minLen, 10 );
1084 arrE[0] = minLen;
1085 } else {
1086 minLen = 0;
1089 switch( tCase.toUpperCase() )
1091 case 'U':
1092 okChars += 'A-Z';
1093 arrE[1] = 'UPPER';
1094 break;
1095 case 'L':
1096 okChars += 'a-z';
1097 arrE[1] = 'lower';
1098 break;
1099 case 'C':
1100 okChars += 'A-Z][a-z';
1101 arrE[1] = 'Intial capital';
1102 minLen--;
1103 break;
1104 default:
1105 okChars += 'a-zA-Z';
1106 break;
1109 if ( numbers == true )
1111 okChars += '0-9';
1112 arrE[2] = 'Yes';
1114 if ( spaces == true )
1116 okChars += ' ';
1117 arrE[3] = 'Yes';
1119 if ( puncs == "any" )
1121 arrE[4] = "Any";
1123 else if ( puncs == "none" )
1125 arrE[4] = "None";
1127 else
1129 puncs = puncs.replace( /pipe/g, "|" );
1130 okChars += puncs;
1131 arrE[4] = puncs; //.toPattern().replace( /\\/g, "" );
1133 var length = ( minLen != "*" )?
1134 "{" + minLen + ",}":
1135 "+";
1136 var regex = ( puncs == "any" ) ?
1137 new RegExp( "^([" + okChars + "]|[^a-zA-Z0-9\\s])" + length + "$" ):
1138 new RegExp( "^[" + okChars + "]" + length + "$" );
1140 if ( !regex.test( this.elem.value ) )
1142 this.throwError( [this.elem.value, this.elem.fName, arrE[0], arrE[1], arrE[2], arrE[3], arrE[4]] );
1145 /*/>*/
1146 /*< equalto logical *******************************************************************/
1147 fValidate.prototype.equalto = function( oName )
1149 if ( this.typeMismatch( 'text' ) ) return;
1150 if ( typeof oName == 'undefined' )
1152 this.paramError( 'oName' );
1154 var otherElem = this.form.elements[oName];
1155 if ( this.elem.value != otherElem.value )
1157 this.throwError( [this.elem.fName,otherElem.fName] );
1160 /*/>*/
1161 /*< ssn extended *******************************************************************/
1162 fValidate.prototype.ssn = function()
1164 if ( this.typeMismatch( 'text' ) ) return;
1165 if ( !( /^\d{3}\-\d{2}\-\d{4}$/.test( this.elem.value ) ) )
1166 this.throwError();
1168 /*/>*/
1169 /*< select controls *******************************************************************/
1170 fValidate.prototype.select = function()
1172 if ( this.typeMismatch( 's1' ) ) return;
1173 if ( this.elem.selectedIndex == 0 )
1175 this.throwError( [this.elem.fName] );
1178 /*/>*/
1179 /*< selectm controls *******************************************************************/
1180 fValidate.prototype.selectm = function( minS, maxS )
1182 if ( this.typeMismatch( 'sm' ) ) return;
1183 if ( typeof minS == 'undefined' )
1185 this.paramError( 'minS' );
1187 if ( maxS == 999 || maxS == '*' || typeof maxS == 'undefined' || maxS > this.elem.length ) maxS = this.elem.length;
1189 var count = 0;
1190 for ( var opt, i = 0; ( opt = this.elem.options[i] ); i++ )
1192 if ( opt.selected ) count++;
1195 if ( count < minS || count > maxS )
1197 this.throwError( [minS, maxS, this.elem.fName, count] );
1200 /*/>*/
1201 /*< selecti controls *******************************************************************/
1202 fValidate.prototype.selecti = function( indexes )
1205 if ( this.typeMismatch( 's1' ) ) return;
1206 if ( typeof indexes == 'undefined' )
1208 this.paramError( 'indexes' );
1209 return;
1211 indexes = indexes.split( "," );
1212 var selectOK = true;
1214 for ( var i = 0; i < indexes.length; i++ )
1216 if ( this.elem.options[indexes[i]].selected )
1218 selectOK = false;
1219 break;
1222 if ( !selectOK )
1224 this.throwError( [this.elem.fName] );
1227 /*/>*/
1228 /*< cazip international *******************************************************************/
1229 fValidate.prototype.cazip = function()
1231 var elem = this.elem;
1232 if ( this.typeMismatch( 'text' ) ) return;
1233 elem.value = elem.value.toUpperCase();
1234 if ( !( /^[A-Z][0-9][A-Z] [0-9][A-Z][0-9]$/.test( elem.value ) ) )
1236 this.throwError();
1239 fValidate.prototype.capost = fValidate.prototype.cazip;
1240 /*/>*/
1241 /*< ukpost international *******************************************************************/
1242 fValidate.prototype.ukpost = function()
1244 var elem = this.elem;
1245 if ( this.typeMismatch( 'text' ) ) return;
1246 elem.value = elem.value.toUpperCase();
1247 if ( !( /^[A-Z]{1,2}\d[\dA-Z] ?\d[A-Z]{2}$/.test( elem.value ) ) )
1249 this.throwError();
1252 /*/>*/
1253 /*< germanpost international *******************************************************************/
1254 fValidate.prototype.germanpost = function()
1256 var elem = this.elem;
1257 if ( this.typeMismatch( 'text' ) ) return;
1258 elem.value = elem.value.toUpperCase();
1259 if ( !( /^(?:CH\-)\d{4}$/.test( elem.value ) ) )
1261 this.throwError();
1264 /*/>*/
1265 /*< swisspost international *******************************************************************/
1266 fValidate.prototype.swisspost = function()
1268 var elem = this.elem;
1269 if ( this.typeMismatch( 'text' ) ) return;
1270 elem.value = elem.value.toUpperCase();
1271 if ( !( /^(?:D\-)\d{5}$/.test( this.elem.value ) ) )
1273 this.throwError();
1276 /*/>*/
1277 /*< email web *******************************************************************/
1278 fValidate.prototype.email = function( level )
1280 if ( this.typeMismatch( 'text' ) ) return;
1281 if ( typeof level == 'undefined' ) level = 0;
1282 var emailPatterns = [
1283 /.+@.+\..+$/i,
1284 /^\w.+@\w.+\.[a-z]+$/i,
1285 /^\w[-_a-z~.]+@\w[-_a-z~.]+\.[a-z]{2}[a-z]*$/i,
1286 /^\w[\w\d]+(\.[\w\d]+)*@\w[\w\d]+(\.[\w\d]+)*\.[a-z]{2,7}$/i
1288 if ( ! emailPatterns[level].test( this.elem.value ) )
1290 this.throwError();
1293 /*/>*/
1294 /*< url web *******************************************************************/
1295 fValidate.prototype.url = function( hosts, hostOptional, allowQS )
1297 if ( this.typeMismatch( 'text' ) ) return;
1299 this.setArg( hosts, "http" );
1301 var front = "^(?:(" + hosts.replace( /\,/g, "|" ) + ")\\:\\/\\/)";
1302 var end = ( Boolean( allowQS ) == true ) ? "(\\?.*)?$" : "$";
1304 if ( Boolean( hostOptional ) == true ) front += "?";
1305 var regex = new RegExp( front + "([\\w\\d-]+\\.?)+" + end );
1307 if ( !regex.test( this.elem.value ) )
1309 this.throwError( [this.elem.fName] );
1312 /*/>*/
1313 /*< ip web *******************************************************************/
1314 fValidate.prototype.ip = function( portMin, portMax )
1316 if ( this.typeMismatch( 'text' ) ) return;
1317 portMin = this.setArg( portMin, 0 );
1318 portMax = this.setArg( portMax, 99999 );
1319 if ( !( /^\d{1,3}(\.\d{1,3}){3}(:\d+)?$/.test( this.elem.value ) ) )
1321 this.throwError();
1323 else
1325 var part, i = 0, parts = this.elem.value.split( /[.:]/ );
1326 while ( part = parts[i++] )
1328 if ( i == 5 ) // Check port
1330 if ( part < portMin || part > portMax )
1332 this.throwError( [part, portMin, portMax], 1 );
1335 else if ( part < 0 || part > 255 )
1337 this.throwError();
1342 /*/>*/
1343 /*< decimal numbers *******************************************************************/
1344 fValidate.prototype.decimal = function( lval, rval )
1346 if ( this.typeMismatch( 'text' ) ) return;
1347 var regex = '', elem = this.elem;
1348 if ( lval != '*' ) lval = parseInt( lval, 10 );
1349 if ( rval != '*' ) rval = parseInt( rval, 10 );
1351 if ( lval == 0 )
1352 regex = "^\\.[0-9]{" + rval + "}$";
1353 else if ( lval == '*' )
1354 regex = "^[0-9]*\\.[0-9]{" + rval + "}$";
1355 else if ( rval == '*' )
1356 regex = "^[0-9]{" + lval + "}\\.[0-9]+$";
1357 else
1358 regex = "^[0-9]{" + lval + "}\\.[0-9]{" + rval + "}$";
1360 regex = new RegExp( regex );
1362 if ( !regex.test( elem.value ) )
1364 this.throwError( [elem.value,elem.fName] );
1367 /*/>*/
1368 /*< decimalr numbers *******************************************************************/
1369 fValidate.prototype.decimalr = function( lmin, lmax, rmin, rmax )
1371 if ( this.typeMismatch( 'text' ) ) return;
1372 lmin = ( lmin == '*' )? 0 : parseInt( lmin, 10 );
1373 lmax = ( lmax == '*' )? '': parseInt( lmax, 10 );
1374 rmin = ( rmin == '*' )? 0 : parseInt( rmin, 10 );
1375 rmax = ( rmax == '*' )? '': parseInt( rmax, 10 );
1376 var decReg = "^[0-9]{"+lmin+","+lmax+"}\\.[0-9]{"+rmin+","+rmax+"}$"
1377 var regex = new RegExp(decReg);
1378 if ( !regex.test( this.elem.value ) )
1380 this.throwError( [this.elem.fName] );
1382 return true;
1384 /*/>*/
1385 /*< zip extended *******************************************************************/
1386 fValidate.prototype.zip = function( sep )
1388 if ( this.typeMismatch( 'text' ) ) return;
1389 sep = this.setArg( sep, "- " );
1390 var regex = new RegExp( "^[0-9]{5}(|[" + sep.toPattern() + "][0-9]{4})?$" );
1391 if ( ! regex.test( this.elem.value ) )
1393 this.throwError();
1396 /*/>*/
1397 /*< phone extended *******************************************************************/
1398 fValidate.prototype.phone = function( format )
1400 if ( this.typeMismatch( 'text' ) ) return;
1401 format = this.setArg( format, 0 );
1402 var patterns = [
1403 /^(\(?\d\d\d\)?)?[ -]?\d\d\d[ -]?\d\d\d\d$/, // loose
1404 /^(\(\d\d\d\) )?\d\d\d[ -]\d\d\d\d$/ // strict
1406 if ( !patterns[format].test( this.elem.value ) )
1408 if ( format == 1 )
1410 this.throwError();
1411 } else {
1412 this.throwError( [], 1 );
1416 /*/>*/
1417 /*< date datetime *******************************************************************/
1418 fValidate.prototype.date = function( formatStr, delim, code, specDate )
1420 if ( this.typeMismatch( 'text' ) ) return;
1421 if ( typeof formatStr == 'undefined' )
1423 this.paramError( 'formatStr' );
1424 return;
1427 delim = this.setArg( delim, "/" );
1429 var error = [this.elem.fName, formatStr.replace( /\//g, delim )];
1430 var format = formatStr.split( "/" );
1431 var compare = this.elem.value.split( delim );
1432 var order = new Object();
1434 for ( var i = 0; i < format.length; i++ )
1436 switch( format[i].charAt( 0 ).toLowerCase() )
1438 case 'm' :
1439 order.months = i;
1440 break;
1441 case 'd' :
1442 order.days = i;
1443 break;
1444 case 'y' :
1445 order.years = i;
1446 break;
1449 var thisDate = new Date( compare[order.years], compare[order.months]-1, compare[order.days] );
1451 if ( isNaN( thisDate ) || thisDate.getDate() != compare[order.days] || thisDate.getMonth() != compare[order.months]-1 || thisDate.getFullYear().toString().length != formatStr.match( /y/g ).length )
1453 this.throwError( error );
1454 return;
1457 var compareElem = this.form.elements[specDate];
1458 if ( typeof compareElem != 'undefined' )
1460 specDate = compareElem.validDate || compareElem.value;
1462 var compareDate = ( specDate == 'today' )?
1463 new Date():
1464 new Date( specDate );
1465 compareDate.setHours(0);
1466 compareDate.setMinutes(0);
1467 compareDate.setSeconds(0);
1468 compareDate.setMilliseconds(0);
1470 var timeDiff = compareDate.getTime() - thisDate.getTime();
1471 var dateOk = false;
1473 switch ( parseInt( code ) ) {
1474 case 1 : // Before specDate
1475 dateOk = Boolean( timeDiff > 0 );
1476 error = 1;
1477 break;
1478 case 2 : // Before or on specDate
1479 dateOk = Boolean( ( timeDiff + 86400000 ) > 0 );
1480 error = 2;
1481 break;
1482 case 3 : // After specDate
1483 dateOk = Boolean( timeDiff < 0 );
1484 error = 3;
1485 break;
1486 case 4 : // After or on specDate
1487 dateOk = Boolean( ( timeDiff - 86400000 ) < 0 );
1488 error = 4;
1489 break;
1490 default : dateOk = true;
1492 if ( !dateOk )
1494 this.throwError( [specDate], error );
1496 this.elem.validDate = thisDate.toString();
1498 /*/>*/
1499 /*< money ecommerce *******************************************************************/
1500 fValidate.prototype.money = function( ds, grp, dml )
1502 if ( this.typeMismatch( 'text' ) ) return;
1504 ds = ( ds == ' ' ) ? false : ds.toPattern();
1505 grp = ( grp == ' ' ) ? false : grp.toPattern();
1506 dml = ( dml == ' ' ) ? false : dml.toPattern();
1508 var moneySyntax, pattern;
1510 switch( true )
1512 case Boolean( ds && grp && dml ): // Dollar sign, grouping, and decimal
1513 pattern = "^" + ds + "(?:(?:[0-9]{1,3}" + grp + ")(?:[0-9]{3}" + grp + ")*[0-9]{3}|[0-9]{1,3})(" + dml + "[0-9]{2})$";
1514 moneySyntax = ds + "XX" + grp + "XXX" + dml + "XX";
1515 break;
1516 case Boolean( ds && grp && !dml ): // Dollar sign and grouping
1517 pattern = "^" + ds + "(?:(?:[0-9]{1,3}" + grp + ")(?:[0-9]{3}" + grp + ")*[0-9]{3}|[0-9]{1,3})$";
1518 moneySyntax = "" + ds + "XX" + grp + "XXX";
1519 break;
1520 case Boolean( ds && !grp && dml ): // Dollar sign and decimal
1521 pattern ="^" + ds + "[0-9]*(\\.[0-9]{2})$";
1522 moneySyntax ="" + ds + "XXXXX" + dml + "XX";
1523 break;
1524 case Boolean( !ds && grp && dml ): // Grouping and decimal
1525 pattern ="^(?:(?:[0-9]{1,3}" + grp + ")(?:[0-9]{3}" + grp + ")*[0-9]{3}|[0-9]{1,3})(" + dml + "[0-9]{2})?$";
1526 moneySyntax ="XX" + grp + "XXX" + dml + "XX";
1527 break;
1528 case Boolean( ds && !grp && !dml ): // Dollar sign only
1529 pattern ="^" + ds + "[0-9]*$";
1530 moneySyntax ="" + ds + "XXXXX";
1531 break;
1532 case Boolean( !ds && grp && !dml ): // Grouping only
1533 pattern ="^(?:(?:[0-9]{1,3}" + grp + ")(?:[0-9]{3}" + grp + ")*[0-9]{3}|[0-9]{1,3})$";
1534 moneySyntax ="XX" + grp + "XXX";
1535 break;
1536 case Boolean( !ds && !grp && dml ): // Decimal only
1537 pattern ="^[0-9]*(" + dml + "[0-9]{2})$";
1538 moneySyntax ="XXXXX" + dml + "XX";
1539 break;
1540 case Boolean( !ds && !grp && !dml ): // No params set, all special chars become optional
1541 pattern ="^.?(?:(?:[0-9]{1,3}.?)(?:[0-9]{3}.?)*[0-9]{3}|[0-9]{1,3})(.[0-9]{2})?$";
1542 moneySyntax ="[?]XX[?]XXX[?XX]";
1545 var regex = new RegExp( pattern );
1546 if ( !regex.test( this.elem.value ) )
1548 this.throwError( [this.elem.fName, moneySyntax.replace( /\\/g, '' )] );
1551 /*/>*/
1552 /*< checkbox controls *******************************************************************/
1553 fValidate.prototype.checkbox = function( minC, maxC )
1555 if ( this.typeMismatch( 'cb' ) ) return;
1556 if ( typeof minC == 'undefined' )
1558 this.paramError( 'minC' );
1559 return;
1561 if ( this.elem == this.form.elements[this.elem.name] && !this.elem.checked )
1563 this.throwError( [this.elem.fName] );
1565 else
1567 this.elem = this.form.elements[this.elem.name];
1568 var len = this.elem.length;
1569 var count = 0;
1571 if ( maxC == 999 || maxC == '*' || typeof maxC == 'undefined' || maxC > this.elem.length )
1573 maxC == len;
1575 var i = len;
1576 while( i-- > 0 )
1578 if ( this.elem[i].checked )
1580 count++;
1583 if ( count < minC || count > maxC )
1585 this.throwError( [minC, maxC, this.elem[0].fName, count] );
1589 /*/>*/
1590 /*< radio controls *******************************************************************/
1591 fValidate.prototype.radio = function()
1593 if ( this.typeMismatch( 'rg' ) ) return;
1594 if ( this.elem == this.form.elements[this.elem.name] && !this.elem.checked )
1596 this.throwError( [this.elem.fName] );
1598 else
1600 this.elem = this.form.elements[this.elem.name];
1602 for ( var i = 0; i < this.elem.length; i++ )
1604 if ( this.elem.item( i ).checked )
1606 return;
1609 this.throwError( [this.elem[0].fName] );
1612 /*/>*/
1613 /*< eitheror logical *******************************************************************/
1614 fValidate.prototype.eitheror = function()
1616 if ( this.typeMismatch( 'hidden' ) ) return;
1617 if ( typeof arguments[0] == 'undefined' )
1619 this.paramError( 'delim' );
1620 return;
1622 if ( typeof arguments[1] == 'undefined' )
1624 this.paramError( 'fields' );
1625 return;
1627 var arg, i = 0,
1628 fields = new Array(),
1629 field,
1630 nbCount = 0,
1631 args = arguments[1].split( arguments[0] );
1633 this.elem.fields = new Array();
1635 while ( arg = args[i++] )
1637 field = this.form.elements[arg];
1638 fields.push( field.fName );
1639 this.elem.fields.push( field );
1641 if ( !this.isBlank( arg ) )
1643 nbCount++;
1646 if ( nbCount != 1 )
1648 this.throwError( [fields.join( "\n\t-" )] );
1651 /*/>*/
1652 /*< atleast logical *******************************************************************/
1653 fValidate.prototype.atleast = function()
1655 if ( this.typeMismatch( 'hidden' ) ) return;
1656 if ( typeof arguments[0] == undefined )
1658 this.paramError( 'qty' );
1659 return;
1661 if ( typeof arguments[1] == undefined )
1663 this.paramError( 'delim' );
1664 return;
1666 if ( typeof arguments[2] == undefined )
1668 this.paramError( 'fields' );
1669 return;
1671 var arg, i = 0,
1672 fields = new Array(),
1673 field,
1674 nbCount = 0,
1675 args = arguments[2].split( arguments[1] );
1677 this.elem.fields = new Array();
1679 while ( arg = args[i++] )
1681 field = this.form.elements[arg];
1682 fields.push( field.fName );
1683 this.elem.fields.push( field );
1685 if ( !this.isBlank( arg ) )
1687 nbCount++;
1690 if ( nbCount < arguments[0] )
1692 this.throwError( [arguments[0], fields.join( "\n\t-" ), nbCount] );
1695 /*/>*/
1696 /*< allornone logical *******************************************************************/
1697 fValidate.prototype.allornone = function()
1699 if ( this.typeMismatch( 'hidden' ) ) return;
1700 if ( typeof arguments[0] == 'undefined' )
1702 this.paramError( 'delim' );
1703 return;
1705 if ( typeof arguments[1] == 'undefined' )
1707 this.paramError( 'fields' );
1708 return;
1710 var arg, i = 0,
1711 fields = new Array(),
1712 field,
1713 nbCount = 0,
1714 args = arguments[1].split( arguments[0] );
1716 this.elem.fields = new Array();
1718 while ( arg = args[i++] )
1720 field = this.form.elements[arg];
1721 fields.push( field.fName );
1722 this.elem.fields.push( field );
1724 if ( !this.isBlank( arg ) )
1726 nbCount++;
1729 if ( nbCount > 0 && nbCount < args.length )
1731 this.throwError( [fields.join( "\n\t-" ), nbCount] );
1734 /*/>*/
1735 /*< comparison logical *******************************************************************/
1736 fValidate.prototype.comparison = function( field1, operator, field2 )
1738 if ( this.typeMismatch( 'hidden' ) ) return;
1739 var elem1 = this.form.elements[field1],
1740 elem2 = this.form.elements[field2],
1741 value1 = this.getValue( elem1 ),
1742 value2 = this.getValue( elem2 );
1743 i18n = this.i18n.comparison;
1744 i = -1;
1746 var operators =
1748 ['>', i18n.gt],
1749 ['<', i18n.lt],
1750 ['>=', i18n.gte],
1751 ['<=', i18n.lte],
1752 ['==', i18n.eq],
1753 ['!=', i18n.neq]
1755 while( operators[++i][0] != operator ){ }
1756 this.elem.fields = [elem1, elem2];
1757 if ( ! eval( value1 + operator + value2 ) )
1759 this.throwError( [elem1.fName, operators[i][1], elem2.fName] );
1762 /*/>*/
1763 /*< file controls *******************************************************************/
1764 fValidate.prototype.file = function( extensions, cSens )
1766 if ( this.typeMismatch( 'file' ) ) return;
1767 if ( typeof extensions == 'undefined' )
1769 this.paramError( 'extensions' );
1770 return;
1772 cSens = Boolean( cSens ) ? "" : "i";
1773 var regex = new RegExp( "^.+\\.(" + extensions.replace( /,/g, "|" ) + ")$", cSens );
1774 if ( ! regex.test( this.elem.value ) )
1776 this.throwError( [extensions.replace( /,/g, "\n" )] );
1779 /*/>*/
1780 /*< custom special *******************************************************************/
1781 fValidate.prototype.custom = function( flags, reverseTest )
1783 if ( this.typeMismatch( 'text' ) ) return;
1784 flags = ( flags ) ? flags.replace( /[^gim]/ig ) : "";
1785 var regex = new RegExp( this.elem.getAttribute( this.config.pattern ), flags );
1786 if ( !regex.test( this.elem.value ) )
1788 this.throwError( [this.elem.fName] );
1791 /*/>*/
1792 /*< cc ecommerce *******************************************************************/
1793 fValidate.prototype.cc = function()
1795 if ( this.typeMismatch( 'text' ) ) return;
1796 var typeElem = this.form.elements[this.config.ccType];
1798 if ( !typeElem )
1800 this.devError( 'noCCType' )
1801 return;
1803 var ccType = typeElem.options[typeElem.selectedIndex].value.toUpperCase();
1805 var types = {
1806 'VISA' : /^4\d{12}(\d{3})?$/,
1807 'MC' : /^5[1-5]\d{14}$/,
1808 'DISC' : /^6011\d{12}$/,
1809 'AMEX' : /^3[4|7]\d{13}$/,
1810 'DINERS' : /^3[0|6|8]\d{12}$/,
1811 'ENROUTE' : /^2[014|149]\d{11}$/,
1812 'JCB' : /^3[088|096|112|158|337|528]\d{12}$/,
1813 'SWITCH' : /^(49030[2-9]|49033[5-9]|49110[1-2]|4911(7[4-9]|8[1-2])|4936[0-9]{2}|564182|6333[0-4][0-9]|6759[0-9]{2})\d{10}(\d{2,3})?$/,
1814 'DELTA' : /^4(1373[3-7]|462[0-9]{2}|5397[8|9]|54313|5443[2-5]|54742|567(2[5-9]|3[0-9]|4[0-5])|658[3-7][0-9]|659(0[1-9]|[1-4][0-9]|50)|844[09|10]|909[6-7][0-9]|9218[1|2]|98824)\d{10}$/,
1815 'SOLO' : /^(6334[5-9][0-9]|6767[0-9]{2})\d{10}(\d{2,3})?$/
1817 if ( typeElem.validated == false && this.groupError == true ) return;
1818 if ( typeof types[ccType] == 'undefined' && typeElem.validated == false && this.groupError == false )
1820 this.devError( [ccType] );
1821 return;
1823 this.elem.value = this.elem.value.replace( /[^\d]/g, "" );
1824 if ( !types[ccType].test( this.elem.value ) || !this.elem.value.luhn() )
1826 this.throwError( [this.elem.fName] );
1830 String.prototype.luhn = function()
1832 var i = this.length;
1833 var checkSum = "", digit;
1834 while ( digit = this.charAt( --i ) )
1836 checkSum += ( i % 2 == 0 ) ? digit * 2 : digit;
1838 checkSum = eval( checkSum.split('').join('+') );
1839 return ( checkSum % 10 == 0 );
1841 /*/>*/
1842 /*< ccDate ecommerce *******************************************************************/
1843 fValidate.prototype.ccDate = function( month, year )
1845 if ( this.typeMismatch( 's1' ) ) return;
1846 year = parseInt( this.getValue( this.form.elements[year] ), 10 ) + 2000;
1847 month = parseInt( this.getValue( this.form.elements[month] ), 10 );
1849 var today = new Date();
1850 var expDate = new Date( year, month )
1852 if ( expDate < today )
1854 alert( ["Card Expired",today,expDate].join( "\n" ) );
1857 /*/>*/
1858 ]]></value>
1859 </data>
1861 </root>