<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>VM Form Validator</title><link>http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator//feed/rss</link><description>VMFormValidator is a JavaScript form validation script based on MooTools 1.3. It aims to provide simple, reliable validation for all form element types across all browsers in an unobtrusive manner.</description><pubDate>Thu, 17 May 2012 00:50:27 +0000</pubDate><lastBuildDate>Thu, 17 May 2012 00:50:27 +0000</lastBuildDate><copyright>asf</copyright><image><url>http://www.virtuosimedia.com/includes/Files/Uploaded/Images/Feeds/avatar80.png</url><title>VM Form Validator</title><link /><width>144</width><height>100</height></image><item><title>VM Form Validator Tutorial</title><description><![CDATA[<p>VMFormValidator is a JavaScript form validation script based on MooTools 1.3. It aims to provide simple, reliable validation for all form element types across all browsers in an unobtrusive manner. It is 100% styled by CSS and allows for custom validations and error messages. Error messages can be displayed above the form, above each input, or below each input. VMFormValidator should not be used as a replacement for server-side validation (using PHP, .NET, etc) because JavaScript can be disabled.</p>
<ul class="actionCall">
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/">About</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/vm-form-validator-api-documentation">Docs</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/vm-form-validator-demos">Demos</a></li>
	<li><a class="primary" href="https://github.com/VirtuosiMedia/VMFormValidator/zipball/master" rel="nofollow">Download</a></li>
</ul>
<h2>Quick Tutorial</h2>
<p>Let&#39;s build a quick registration form and validate it. VMFormValidator requires the MooTools library, so we&#39;ll need to download the entire <a href="http://mootools.net/core" rel="nofollow">MooTools 1.3 Core file</a>. Go download it quickly if you don&#39;t already have it. Don&#39;t forget to download a copy of VMFormValidator as well.</p>
<p>If you&#39;re new to JavaScript (or MooTools), you&#39;ll find the implementation of VMFormValidator fairly easy. It&#39;s important to note that VMFormValidator has only two requirements for the form: 1) the form must have an id; 2) the form must use labels. Other than that, you&#39;re free to style the form however you like. We&#39;ll start with constructing our HTML form. For this basic registration form, we&#39;re only going to use 4 fields: username, password, passwordConfirm, and email.</p>
<pre class="html">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
&lt;title&gt;VMFormValidatorTutorial&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
	&lt;form id=&quot;registration&quot; method=&quot;post&quot; action=&quot;&quot;&gt;
		&lt;label for=&quot;username&quot;&gt;Username&lt;/label&gt;
		&lt;input id=&quot;username&quot; name=&quot;username&quot; type=&quot;text&quot; /&gt;
		&lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;
		&lt;input id=&quot;password&quot; name=&quot;password&quot; type=&quot;password&quot; /&gt;
		&lt;label for=&quot;confirmPassword&quot;&gt;Confirm Password&lt;/label&gt;
		&lt;input id=&quot;confirmPassword&quot; name=&quot;confirmPassword&quot; type=&quot;password&quot; /&gt;
		&lt;label for=&quot;email&quot;&gt;Email&lt;/label&gt;
		&lt;input id=&quot;email&quot; name=&quot;email&quot; type=&quot;text&quot; /&gt;
		&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
	&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>That was pretty easy, right? Let&#39;s go ahead and add just a little CSS styling to make our form look better (though we won&#39;t go overboard). For this tutorial, we&#39;re just going to put it in the head of our XHTML document, but in practice we recommend putting in your stylesheet in a separate file.</p>
<pre class="css">&lt;style type=&quot;text/css&quot;&gt;
	input, label, .errorList {float:left; clear:left;}
&lt;/style&gt;
</pre>
<p>Next we need to add our JavaScript files, MooTools1.2-core.js and VMFormValidator1.0.js. We&#39;ll put those in the document head as well.</p>
<pre class="html">&lt;script type=&quot;text/javascript&quot; src=&quot;mootools-1.2-core.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;VMFormValidator1.0.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
<p>Now we need to add a little bit of MooTools specific JavaScript. MooTools has a special event called &#39;domready&#39; that executes whenever the HTML has finished loading. Most MooTools scripts are at least partially executed from within the &#39;domready&#39; event. Again, we&#39;re just going to put this code in the document head, but it could also be in its own file.</p>
<pre class="html">&lt;script type=&quot;text/javascript&quot;&gt;
	window.addEvent(&#39;domready&#39;, function(){
		//Our validation code will go here
	});
&lt;/script&gt;
</pre>
<p>All of our validation code is going to be inserted into the &#39;domready&#39; event, right where the comment currently is. The first thing we&#39;ll need to do is initialize the VMFormValidator class. In this case, we&#39;ll use the variable <em>form</em>, but you can use <em>register</em>, or <em>form1</em>, or whatever you like. We&#39;ll set <em>form</em> equal to a new instance of VMFormValidator. Because the constructor for the VMFormValidator class has one required argument, the form id, we&#39;re going to enter in our form id of &#39;registration&#39;, surrounded in quotes to make it a string.</p>
<pre class="html">&lt;script type=&quot;text/javascript&quot;&gt;
	window.addEvent(&#39;domready&#39;, function(){
		var form = new VMFormValidator(&#39;registration&#39;);
	});
&lt;/script&gt;
</pre>
<p>The constructor for VMFormValidator also has an optional argument for options, but we&#39;ll cover that a little later. Next, we&#39;re going make all of our form fields required. To do that, we&#39;ll use VMFormValidator&#39;s <em><a href="#required">required</a></em> method. The <em>required</em> method has one required argument, the field name we want to be required, and one optional argument, the error. Almost every method has a default error that it displays, but we can customize it if we want. We&#39;ll customize it only for the username and password fields.</p>
<pre class="js">&lt;script type=&quot;text/javascript&quot;&gt;
	window.addEvent(&#39;domready&#39;, function(){
		var form = new VMFormValidator(&#39;registration&#39;);
		form.required(&#39;username&#39;, &#39;Please enter a username.&#39;); //Custom error
		form.required(&#39;password&#39;, &#39;Please enter a password.&#39;); //Custom error
		form.required(&#39;confirmPassword&#39;); //Default error
		form.required(&#39;email&#39;);	//Default error			
	});
&lt;/script&gt;
</pre>
<p>Go ahead and try out your script now. It should be validating for each field, with an error message appearing below each input element if you don&#39;t type in it. If there are any problems, check to make sure that the paths to your javascript files are correct and that each one of the arguments entered above are in string format. While we&#39;re on the subject of arguments, if you look closely at the documentation, you&#39;ll see that VMFormValidator uses 3 other kinds of arguments: boolean (which is either true or false), integer (a whole number), and object (usually in an array format).</p>
<p>Let&#39;s add a few more validations to our form. For the <em>username</em> field, we&#39;ll add <a href="#alphanumeric">alphanumeric</a> and <a href="#range">range</a>. For the <em>password</em> field, we&#39;ll add <a href="#noMatches">noMatches</a> and <a href="#password">password</a>. For <em>confirmPassword</em>, we&#39;ll add <a href="#matches">matches</a>, and for <em>email</em>, we&#39;ll add <a href="#email">email</a>.</p>
<pre class="js">&lt;script type=&quot;text/javascript&quot;&gt;
	window.addEvent(&#39;domready&#39;, function(){
		var form = new VMFormValidator(&#39;registration&#39;);
		form.required(&#39;username&#39;, &#39;Please enter a username.&#39;); //Custom error
		form.alphanumeric(&#39;username&#39;); //Default error
		form.range(&#39;username&#39;, 4, 10) //Default error
		form.required(&#39;password&#39;, &#39;Please enter a password.&#39;); //Custom error
		form.noMatches(&#39;password&#39;, &#39;username&#39;, &#39;The password and username cannot be the same.&#39;); //Custom Error
		form.password(&#39;password&#39;); //Default error
		form.required(&#39;confirmPassword&#39;); //Default error
		form.matches(&#39;confirmPassword&#39;, &#39;password&#39;, &#39;Passwords must match.&#39;); //Custom error
		form.required(&#39;email&#39;);	//Default error
		form.email(&#39;email&#39;); //Default error			
	});
&lt;/script&gt;
</pre>
<p>That&#39;s all there is to it! Try your form again and try to sneak past it (without disabling JavaScript). We could stop there, but I&#39;ll show you just a few more things VMFormValidator can do.</p>
<p>Like I mentioned earlier, VMFormValidator has options. The default CSS class names VMFormValidator uses are <em>.successLabel</em>, <em>.successElement</em>, <em>.errorLabel</em>, <em>.errorElement</em>, <em>.errorList</em>, and <em>.errorListItem</em>. Let&#39;s add a little more style to our form by adding to our CSS:</p>
<pre class="js">&lt;style type=&quot;text/css&quot;&gt;
	input, label, .errorList {float:left; clear:left;}
	.successLabel {color:#006600;}
	.successElement {border:#006600 1px solid;}
	.errorLabel, .errorListItem {color:#FF0000;}
	.errorElement {border:#FF0000 1px solid;}	
&lt;/style&gt;
</pre>
<p>If you don&#39;t like the class names VMFormValidator uses, you can change them by specifying them in the class constructor. To do that, we&#39;re going to use our optional argument for the VMFormValidator contructor method. Because the optional argument accepts more than one option, we need to enclose it in an object. That simply means we&#39;ll put curly braces {} around our entire set of options. Each option has two parts: the option name and its value, which are separated by a colon. If you have more than one option, each option should be separated by a comma, except the last one. Sound complicated? It&#39;s actually easier than it sounds. Let&#39;s take a look at an example:</p>
<pre class="js">&lt;script type=&quot;text/javascript&quot;&gt;
	window.addEvent(&#39;domready&#39;, function(){
		var form = new VMFormValidator(&#39;registration&#39;, {
			disableSubmit: false,
			errorDisplay: &#39;aboveForm&#39;
		});
		form.required(&#39;username&#39;, &#39;Please enter a username.&#39;); //Custom error
		form.alphanumeric(&#39;username&#39;); //Default error
		form.range(&#39;username&#39;, 4, 10) //Default error
		form.required(&#39;password&#39;, &#39;Please enter a password.&#39;); //Custom error
		form.noMatches(&#39;password&#39;, &#39;username&#39;, &#39;The password and username cannot be the same.&#39;); //Custom Error
		form.password(&#39;password&#39;); //Default error
		form.required(&#39;confirmPassword&#39;); //Default error
		form.matches(&#39;confirmPassword&#39;, &#39;password&#39;, &#39;Passwords must match.&#39;); //Custom error
		form.required(&#39;email&#39;);	//Default error
		form.email(&#39;email&#39;); //Default error			
	});
&lt;/script&gt;
</pre>
<p>The above code tells VMFormValidator that the submit button should not be disabled if there is an error and that all errors should be displayed above the form. The CSS classes can be specified in the same way if you don&#39;t like the defaults. For a full list of options, see the <a href="#constructor">constructor</a> method.</p>
<p>With that, our tutorial draws to a close. If you want to dig deeper into VMFormValidator, the documentation below provides examples for each method, along with the method syntax and argument types. I hope VMFormValidator will be a worthy solution for your forms. If you encounter a bug, have a question or comment, feel free to contact us. If you liked VMFormValidator, tell someone else about it. Thanks, and enjoy!</p>
]]></description><link>http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/vm-form-validator-tutorial</link><category>VM Form Validator</category><pubDate>Tue, 08 Mar 2011 19:33:00 +0000</pubDate></item><item><title>VM Form Validator API Documentation</title><description><![CDATA[<p>VMFormValidator is a JavaScript form validation script based on MooTools 1.3. It aims to provide simple, reliable validation for all form element types across all browsers in an unobtrusive manner. It is 100% styled by CSS and allows for custom validations and error messages. Error messages can be displayed above the form, above each input, or below each input. VMFormValidator should not be used as a replacement for server-side validation (using PHP, .NET, etc) because JavaScript can be disabled.</p>
<ul class="actionCall">
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/">About</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/vm-form-validator-tutorial">Tutorial</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/vm-form-validator-demos">Demos</a></li>
	<li><a class="primary" href="https://github.com/VirtuosiMedia/VMFormValidator/zipball/master" rel="nofollow">Download</a></li>
</ul>
<h2>Docs</h2>
<p><a class="smoothscroll" name="VMFormValidator"></a></p>
<h2><a class="smoothscroll" name="VMFormValidator">Class: VMFormValidator</a></h2>
<p>This class is for validating forms.</p>
<h3>Implements:</h3>
<ul>
	<li><a href="http://docs.mootools.net/Class/Class.Extras#Events" rel="nofollow">Events</a>, <a href="http://docs.mootools.net/Class/Class.Extras#Options" rel="nofollow">Options</a></li>
</ul>
<h3>Notes:</h3>
<ul>
	<li><a href="http://www.w3.org/TR/html401/interact/forms.html#h-17.9" rel="nofollow">According to the W3C</a>, the &#39;for&#39; attribute for a label should refer to a form element&#39;s id, <em><strong>not</strong></em> the element&#39;s name. A good practice is to give your form elements an id that matches their names. This will ensure that your markup validates, while also reducing any chances of confusion in regards to a naming schema.</li>
</ul>
<p><a class="smoothscroll" name="constructor"></a></p>
<h2><a class="smoothscroll" name="constructor">VMFormValidator Method: constructor</a></h2>
<p>VMFormValidator is completely unobtrusive and requires no changes to existing markup, provided the form has an id and uses labels.</p>
<h3>Syntax:</h3>
<pre class="js">var form = new VMFormValidator(formId[, options]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>formId - (<em>string</em>) The id of the form on which validation should be performed.</li>
	<li>options - (<em>object</em>, optional) Any of the options below.</li>
</ol>
<h4>Options:</h4>
<ul>
	<li>disableSubmit - (<em>boolean</em>, defaults to true) Disable the submit button on validation failure.</li>
	<li>errorDisplay - (<em>string</em>, defaults to &#39;belowInput&#39;) Where the errors are displayed. Acceptable values are: &#39;aboveInput&#39;, &#39;belowInput&#39;, and &#39;aboveForm&#39;.</li>
	<li>errorDisplayMultiple - (<em>boolean</em>, defaults to false) Display multiple errors at a time per element</li>
	<li>errorListClass - (<em>string</em>, defaults to &#39;errorList&#39;) Class for the error display list.</li>
	<li>errorListItemClass - (<em>string</em>, defaults to &#39;errorListItem&#39;) Class for each error display list item.</li>
	<li>errorElement - (<em>string</em>, defaults to &#39;errorElement&#39;) Class for the form element when an error is detected.</li>
	<li>errorLabel - (<em>string</em>, defaults to &#39;errorLabel&#39;) Class for the form element label when an error is detected.</li>
	<li>labelDisplay - (<em>string</em>, defaults to &#39;before&#39;) Where the label is in relation to the form element in the HTML: &#39;before&#39;, &#39;after&#39;.</li>
	<li>successElementClass - (<em>string</em>, defaults to &#39;successElement&#39;) Class for the input box when validation succeeds.</li>
	<li>successLabelClass - (<em>string</em>, defaults to &#39;successLabel&#39;) Class for the input label when validation succeeds.</li>
	<li>validateOnBlur - (<em>boolean</em>, defaults to &#39;true&#39;) Validate each form element on blur.</li>
	<li>validateOnSubmit - (<em>boolean</em>, defaults to &#39;true&#39;) Validate each form element on submit.</li>
</ul>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
});
</pre>
<h3>Notes:</h3>
<ul>
	<li>Any form using VMFormValidator <em>must</em> have an id and labels <em>must</em> be used for all form elements that are validated.</li>
	<li>VMFormValidator must be placed within the &#39;domready&#39; event.</li>
	<li>For multiple forms, you must use multiple instances of the class.</li>
	<li>When using multiple forms, take care that no form elements share the same name or the errors will not appear in the second form.</li>
</ul>
<p><a class="smoothscroll" name="addFunction"></a></p>
<h2><a class="smoothscroll" name="addFunction">VMFormValidator Method: addFunction</a></h2>
<p>Adds a custom function to the onBlur and onSubmit events, to be run with the rest of the validations.</p>
<h3>Syntax:</h3>
<pre class="js">form.addFunction(name, customFunction);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the custom function should be applied.</li>
	<li>customFunction - (<em>string</em>) The function which should be applied for both onBlur and onSubmit events (if they are enabled) for the form element. The <em>customFunction</em> must be in string format because it is later executed using eval.</li>
</ol>
<h3>Example:</h3>
<pre class="js">var custom_function = function(){
	alert(&#39;This is a custom function&#39;);
}

window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.addFunction(&#39;firstName&#39;, &#39;custom_function()&#39;);
});
</pre>
<h3>Notes:</h3>
<ul>
	<li>The custom function should be defined outside the &#39;domready&#39; event.</li>
</ul>
<p><a class="smoothscroll" name="alpha"></a></p>
<h2><a class="smoothscroll" name="alpha">VMFormValidator Method: alpha</a></h2>
<p>Validates alphabetic characters.</p>
<h3>Syntax:</h3>
<pre class="js">form.alpha(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field may contain only letters.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.alpha(&#39;firstName&#39;); //Default error
	form.alpha(&#39;lastName&#39;, &#39;Please enter only letters for your last name&#39;); //Custom error
});
</pre>
<p><a class="smoothscroll" name="alphanumeric"></a></p>
<h2><a class="smoothscroll" name="alphanumeric">VMFormValidator Method: alphanumeric</a></h2>
<p>Validates alphanumeric characters.</p>
<h3>Syntax:</h3>
<pre class="js">form.alphanumeric(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field may contain only letters or numbers.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.alphanumeric(&#39;code&#39;); //Default error
	form.alphanumeric(&#39;code&#39;, &#39;Code can contain only letters or numbers.&#39;); //Custom error
});
</pre>
<p><a class="smoothscroll" name="canadaPostal"></a></p>
<h2><a class="smoothscroll" name="canadaPostal">VMFormValidator Method: canadaPostal</a></h2>
<p>Validates Canadian Postal codes.</p>
<h3>Syntax:</h3>
<pre class="js">form.canadaPostal(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Please enter a valid Canadian Postal Code.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.canadaPostal(&#39;postal&#39;); //Default error
	form.canadaPostal(&#39;postal&#39;, &#39;You don&#39;t really live in Canada, do you?&#39;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#usZip">usZip</a></li>
</ul>
<p><a class="smoothscroll" name="credit"></a></p>
<h2><a class="smoothscroll" name="credit">VMFormValidator Method: credit</a></h2>
<p>Validates all major credit card types including Visa, Mastercard, American Express, and Discover.</p>
<h3>Syntax:</h3>
<pre class="js">form.credit(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Please enter a valid credit card number.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.credit(&#39;credit&#39;); //Default error
	form.credit(&#39;credit&#39;, &#39;That must have been your library card number. Try again.&#39;); //Custom error
});
</pre>
<p><a class="smoothscroll" name="dateMDY"></a></p>
<h2><a class="smoothscroll" name="dateMDY">VMFormValidator Method: dateMDY</a></h2>
<p>Validates a date in Month/Day/Year format. Accepts spaces, hyphens, forward slashes, or periods as seperators.</p>
<h3>Syntax:</h3>
<pre class="js">form.dateMDY(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Please enter a valid date in M/D/Y format.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.dateMDY(&#39;date&#39;); //Default error
	form.dateMDY(&#39;date&#39;, &#39;Not a prune. A date.&#39;); //Custom error
});
</pre>
<p><a class="smoothscroll" name="dateYMD"></a></p>
<h2><a class="smoothscroll" name="dateYMD">VMFormValidator Method: dateYMD</a></h2>
<p>Validates a date in Year/Month/Day format. Accepts spaces, hyphens, forward slashes, or periods as seperators.</p>
<h3>Syntax:</h3>
<pre class="js">form.dateYMD(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Please enter a valid date in Y/M/D format.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.dateYMD(&#39;date&#39;); //Default error
	form.dateYMD(&#39;date&#39;, &#39;If I have to pay, it isn&#39;t a real date.&#39;); //Custom error
});
</pre>
<p><a class="smoothscroll" name="email"></a></p>
<h2><a class="smoothscroll" name="email">VMFormValidator Method: email</a></h2>
<p>Validates most email addresses.</p>
<h3>Syntax:</h3>
<pre class="js">form.email(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Please enter a valid email address.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.email(&#39;email&#39;); //Default error
	form.email(&#39;email&#39;, &#39;Did you want me to guess your email address?.&#39;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#url">url</a></li>
</ul>
<p><a class="smoothscroll" name="excludes"></a></p>
<h2><a class="smoothscroll" name="excludes">VMFormValidator Method: excludes</a></h2>
<p>Will return an error if any of the array values are present.</p>
<h3>Syntax:</h3>
<pre class="js">form.excludes(name, arrayCheck[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>arrayCheck - (<em>array</em>) Values that should return an error if they are present.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field cannot contain any of the following values: arrayCheck[].&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.excludes(&#39;spam&#39;, [&#39;get rich quick&#39;, &#39;affiliate&#39;, &#39;millions&#39;]); //Default error
	form.excludes(&#39;spam&#39;, [&#39;lottery&#39;, &#39;Nigeria&#39;, &#39;dead relative&#39;], &#39;So sorry, we already made our millions.&#39;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#includes">includes</a></li>
</ul>
<p><a class="smoothscroll" name="imageFile"></a></p>
<h2><a class="smoothscroll" name="imageFile">VMFormValidator Method: imageFile</a></h2>
<p>Validate a file upload input to see if the file is an image.</p>
<h3>Syntax:</h3>
<pre class="js">form.imageFile(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Please upload a valid image file. Valid files end with one of the following extensions: .jpg, .jpeg, .bmp, .gif, .png.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.imageFile(&#39;photo&#39;); //Default error
	form.imageFile(&#39;photo&#39;, &#39;Photos only, please. With a signature, they&#39;re only $10 apiece.&#39;); //Custom error
});
</pre>
<p><a class="smoothscroll" name="includes"></a></p>
<h2><a class="smoothscroll" name="includes">VMFormValidator Method: includes</a></h2>
<p>Will return an error if any of the array values are not present.</p>
<h3>Syntax:</h3>
<pre class="js">form.includes(name, arrayCheck[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>arrayCheck - (<em>array</em>) Values that should return an error if one or more are not present.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field did not contain any of the following values: arrayCheck[].&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.includes(&#39;comments&#39;, [&#39;I love Virtuosi Media&#39;, &#39;thank you&#39;, &#39;biggest fan&#39;]); //Default error
	form.includes(&#39;comments&#39;, [&#39;I love Virtuosi Media&#39;, &#39;thank you&#39;, &#39;biggest fan&#39;], &#39;Don&#39;t you love us?&#39;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#excludes">excludes</a></li>
</ul>
<p><a class="smoothscroll" name="matches"></a></p>
<h2><a class="smoothscroll" name="matches">VMFormValidator Method: matches</a></h2>
<p>Compares the values of two fields and returns an error if they do not match. Useful for confirming a password.</p>
<h3>Syntax:</h3>
<pre class="js">form.matches(name, compareName[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>compareName - (<em>string</em>) The name of the form element which <em>name</em> should match.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field does not match the <em>compareName</em> field.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.matches(&#39;password&#39;, &#39;confirmPassword&#39;); //Default error
	form.matches(&#39;password&#39;, &#39;confirmPassword&#39;, &#39;Forget already? Not a good sign...&#39;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#noMatches">noMatches</a></li>
</ul>
<p><a class="smoothscroll" name="maxLength"></a></p>
<h2><a class="smoothscroll" name="maxLength">VMFormValidator Method: maxLength</a></h2>
<p>Sets a maximum length for a field.</p>
<h3>Syntax:</h3>
<pre class="js">form.maxLength(name, maxLength[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>maxLength - (<em>integer</em>) The maximum number of characters to be entered into the form element.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field may contain no more than <em>maxLength</em> characters.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.maxLength(&#39;name&#39;, 50); //Default error
	form.maxLength(&#39;name&#39;, 50, &#39;Helloooo Hemingway.&#39;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#minLength">minLength</a>, <a href="#range">range</a></li>
</ul>
<p><a class="smoothscroll" name="minLength"></a></p>
<h2><a class="smoothscroll" name="minLength">VMFormValidator Method: minLength</a></h2>
<p>Sets a minimum length for a field.</p>
<h3>Syntax:</h3>
<pre class="js">form.minLength(name, minLength[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>minLength - (<em>integer</em>) The minimum number of characters to be entered into the form element.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field must contain at least <em>minLength</em> characters.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.minLength(&#39;name&#39;, 4); //Default error
	form.minLength(&#39;name&#39;, 4, &quot;Stingy, aren&#39;t we? Type at least four characters, please.&quot;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#maxLength">maxLength</a>, <a href="#range">range</a></li>
</ul>
<p><a class="smoothscroll" name="noMatches"></a></p>
<h2><a class="smoothscroll" name="noMatches">VMFormValidator Method: noMatches</a></h2>
<p>Compares the values of two fields and returns an error if they match. Useful making sure a password doesn&#39;t match a username.</p>
<h3>Syntax:</h3>
<pre class="js">form.noMatches(name, compareName[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>compareName - (<em>string</em>) The name of the form element which <em>name</em> cannot match.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field cannot match the <em>compareName</em> field.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.noMatches(&#39;password&#39;, &#39;username&#39;); //Default error
	form.noMatches(&#39;password&#39;, &#39;username&#39;, &quot;That&#39;s like asking to be hacked.&quot;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#matches">matches</a></li>
</ul>
<p><a class="smoothscroll" name="numeric"></a></p>
<h2><a class="smoothscroll" name="numeric">VMFormValidator Method: numeric</a></h2>
<p>Validate if a form element&#39;s value is numeric.</p>
<h3>Syntax:</h3>
<pre class="js">form.numeric(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field may contain only numbers.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.numeric(&#39;page&#39;); //Default error
	form.numeric(&#39;page&#39;, &quot;I can always count on you to type something you&#39;re not supposed to. Please enter only numbers.&quot;); //Custom error
});
</pre>
<h3>Notes:</h3>
<ul>
	<li><em>numeric</em> checks only for numbers; periods and commas will cause an error.</li>
</ul>
<h3>See also:</h3>
<ul>
	<li><a href="#alphanumeric">alphanumeric</a></li>
</ul>
<p><a class="smoothscroll" name="password"></a></p>
<h2><a class="smoothscroll" name="password">VMFormValidator Method: password</a></h2>
<p>Validates a password of at least one lowercase letter, one uppercase letter, and one number. The password must be at least 6 characters long.</p>
<h3>Syntax:</h3>
<pre class="js">form.password(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Your password must contain one lowercase letter, one uppercase letter, one number, and be at least 6 characters long.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.password(&#39;password&#39;); //Default error
	form.password(&#39;password&#39;, &quot;That&#39;s probably your cat&#39;s name, isn&#39;t it? Try something a little harder to crack.&quot;); //Custom error
});
</pre>
<p><a class="smoothscroll" name="phone"></a></p>
<h2><a class="smoothscroll" name="phone">VMFormValidator Method: phone</a></h2>
<p>Validates a North American phone number, with the area code required. Allows for optional spaces, hyphens, or periods as separators and parentheses for the area code. A leading one or zero is also optional.</p>
<h3>Syntax:</h3>
<pre class="js">form.phone(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Please enter a valid phone number including area code.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.phone(&#39;phone&#39;); //Default error
	form.phone(&#39;phone&#39;, &quot;Please? We promise we won&#39;t call.&quot;); //Custom error
});
</pre>
<p><a class="smoothscroll" name="range"></a></p>
<h2><a class="smoothscroll" name="range">VMFormValidator Method: range</a></h2>
<p>Sets a minimum length for a field.</p>
<h3>Syntax:</h3>
<pre class="js">form.range(name, minLength, maxLength[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>minLength - (<em>integer</em>) The minimum number of characters to be entered into the form element.</li>
	<li>maxLength - (<em>integer</em>) The maximum number of characters to be entered into the form element.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field must contain at least <em>minLength</em> and no more than <em>maxLength</em> characters.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.range(&#39;password&#39;, 4, 10); //Default error
	form.range(&#39;password&#39;, 4, 10, &quot;Let&#39;s compromise. Not too long. Not too short.&quot;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#maxLength">maxLength</a>, <a href="#minLength">minLength</a></li>
</ul>
<p><a class="smoothscroll" name="required"></a></p>
<h2><a class="smoothscroll" name="required">VMFormValidator Method: required</a></h2>
<p>Makes any form element required.</p>
<h3>Syntax:</h3>
<pre class="js">form.required(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;This field is required.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.required(&#39;creditCard&#39;); //Default error
	form.required(&#39;creditCard&#39;, &quot;Payment is required.&quot;); //Custom error
});
</pre>
<h3>Notes:</h3>
<ul>
	<li>Radio buttons are a special case in form validation because the tab index works differently across browsers. Internet Explorer, Safari, and Google Chrome will tab through only the first radio in a series, while Firefox and Opera will tab through each radio. VMFormValidator handles the cross browser validation for radios, ensuring that no false errors will be produced when the tab index hasn&#39;t finished cycling through a radio series in Firefox and Opera.</li>
</ul>
<p><a class="smoothscroll" name="swearFilter"></a></p>
<h2><a class="smoothscroll" name="swearFilter">VMFormValidator Method: swearFilter</a></h2>
<p>Triggers an error if a common swear word is present in a form element.</p>
<h3>Syntax:</h3>
<pre class="js">form.swearFilter(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Please refrain from using profanity.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.swearFilter(&#39;comments&#39;); //Default error
	form.swearFilter(&#39;comments&#39;, &quot;That wasn&#39;t a very nice thing to say.&quot;); //Custom error
});
</pre>
<h3>Notes:</h3>
<ul>
	<li>For a more comprehensive swear filter, use the <a href="#excludes">excludes</a> method to define your own set of words.</li>
</ul>
<h3>See also:</h3>
<ul>
	<li><a href="#excludes">excludes</a></li>
</ul>
<p><a class="smoothscroll" name="url"></a></p>
<h2><a class="smoothscroll" name="url">VMFormValidator Method: url</a></h2>
<p>Validates most URLs.</p>
<h3>Syntax:</h3>
<pre class="js">form.url(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Please enter a valid URL.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.url(&#39;website&#39;); //Default error
	form.url(&#39;website&#39;, &quot;What part of 404 don&#39;t you understand?&quot;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#email">email</a></li>
</ul>
<p><a class="smoothscroll" name="usZip"></a></p>
<h2><a class="smoothscroll" name="usZip">VMFormValidator Method: usZip</a></h2>
<p>Validates US ZIP codes. The four digit ZIP code extension is optional.</p>
<h3>Syntax:</h3>
<pre class="js">form.usZip(name[, error]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>, optional) The error message to be displayed on validation failure. Default message: &quot;Please enter a valid US ZIP Code.&quot;</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.usZip(&#39;zip&#39;); //Default error
	form.usZip(&#39;zip&#39;, &#39;Bonus points if you can enter a correct ZIP code AND tell me what ZIP stands for.&#39;); //Custom error
});
</pre>
<h3>See also:</h3>
<ul>
	<li><a href="#canadaPostal">canadaPostal</a></li>
</ul>
<p><a class="smoothscroll" name="validateRegEx"></a></p>
<h2><a class="smoothscroll" name="validateRegEx">VMFormValidator Method: validateRegEx</a></h2>
<p>Validates a custom regular expression.</p>
<h3>Syntax:</h3>
<pre class="js">form.validateRegEx(regex, name, error);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>regex - (<em>string</em>) A regex to evaluated.</li>
	<li>name - (<em>string</em>) The name of the form element to which the validation should be applied.</li>
	<li>error - (<em>string</em>) The error message to be displayed on validation failure. There is <em><strong>no</strong></em> default message.</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var form = new VMFormValidator(&#39;exampleForm&#39;);
	form.validateRegEx(&#39;mootools&#39;, &#39;favorite&#39;, &quot;You must type &#39;MooTools.&#39;&quot;); 
});
</pre>
<h3>Further JavaScript Regular Expression Resources:</h3>
<ul>
	<li><a href="http://www.regular-expressions.info/javascript.html" rel="nofollow">http://www.regular-expressions.info/javascript.html</a> - Specifics of writing regular expressions for JavaScript.</li>
	<li><a href="http://regexlib.com/" rel="nofollow">http://regexlib.com/</a> - A regular expression library. Be sure to check out their cheat sheet.</li>
</ul>
]]></description><link>http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/vm-form-validator-api-documentation</link><category>VM Form Validator</category><pubDate>Tue, 08 Mar 2011 19:46:00 +0000</pubDate></item><item><title>VM Form Validator Demos</title><description><![CDATA[<p>VMFormValidator is a JavaScript form validation script based on MooTools 1.3. It aims to provide simple, reliable validation for all form element types across all browsers in an unobtrusive manner. It is 100% styled by CSS and allows for custom validations and error messages. Error messages can be displayed above the form, above each input, or below each input. VMFormValidator should not be used as a replacement for server-side validation (using PHP, .NET, etc) because JavaScript can be disabled.</p>
<ul class="actionCall">
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/">About</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/vm-form-validator-tutorial">Tutorial</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/vm-form-validator-api-documentation">Docs</a></li>
	<li><a class="primary" href="https://github.com/VirtuosiMedia/VMFormValidator/zipball/master" rel="nofollow">Download</a></li>
</ul>
<h2>Registration</h2>
<p>This sample registration form will validate all fields and will not let the form be submitted until all fields are properly filled out. <strong>(Note: You must press the &quot;Run&quot; button to use the demo).</strong></p>
<p><iframe src="http://jsfiddle.net/gh/get/mootools/1.3/VirtuosiMedia/VMFormValidator/tree/master/Demos/Register/" style="width: 954px; height: 600px;"></iframe></p>
<h2>Survey</h2>
<p>This sample survey form will validate all fields and will not let the form be submitted until all fields are properly filled out. Note that Firefox and Opera handle radio button tabbing differently than Internet Explorer, Chrome, and Safari.&nbsp;<strong>(Note: You must press the &quot;Run&quot; button to use the demo).</strong></p>
<p><iframe src="http://jsfiddle.net/gh/get/mootools/1.3/VirtuosiMedia/VMFormValidator/tree/master/Demos/Survey/" style="width: 954px; height: 600px;"></iframe></p>
Hi Mom!]]></description><link>http://www.virtuosimedia.com/dev/javascript/mootools-plugins/vm-form-validator/vm-form-validator-demos</link><category>VM Form Validator</category><pubDate>Tue, 08 Mar 2011 20:23:00 +0000</pubDate></item></channel></rss>
