Installation

SharePoint Validator requires jQuery. The current version was built against jQuery 1.3.2, but should work with all versions thereafter, and possibly some versions prior.

Download the latest edition of SharePointValidator.js and install the file somewhere accessible to your SharePoint Server along with the latest jQuery library.

Usage

In order to use SharePoint Validator on NewForm.aspx or EditForm.aspx pages, go to the NewForm.aspx page for the list you would like to use, and add ?toolpaneview=2 after the URL.

For example, if your list URL to add a new item was http://mysharepoint.com/Lists/MyList/NewForm.aspx you would add ?toolpaneview=2 after the URL, so your entire URL to load would be http://mysharepoint.com/Lists/MyList/NewForm.aspx?toolpaneview=2.

After loading this page you will have the ability to add a new Web Part to the page.

Click the "Add a Web Part" link, and add a Content Editor Web Part to the page.

Select edit -> Modify Shared Web Part.

Click "Source Editor..." to open a source view for the Content Editor Web Part.

Paste the following in this field:

<script type="text/javascript" src="\path\to\jquery.min.js"></script>
<script type="text/javascript" src="\path\to\SharePointValidator.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var validator = new SharePointValidator();
validator.addRequired("First Name");
validator.addRequired("Last Name");
validator.addRequired("Title");

validator.addPhoneNumber("Phone Number");
validator.addPhoneNumber("Fax Number");

validator.addZipCode("Zip");

validator.addEmailAddress("Email Address");

$("input").blur(function() { validator.validate(); });
validator.validate();
});
</script>

This will load jQuery, SharePointValidator, and add the fields to be validated.

The blur() event tells it to re-validate each time a field is left. This can be altered so you can validate on any event as desired. The second call to validate() tells it to immediately validate the form upon loading.

Please note that validator will also automatically disable the OK button until all fields are properly input.

Another important thing to note is that any EmailAddress, Zip Code, or Phone validation automatically adds the input to the Required validation fields as well. So explicitly calling .addRequired() to any regex validation is not required.

For further information, you may contact Tom via Twitter at @nerdyhearn or via his website at http://www.nerdyhearn.com


Last edited Feb 2, 2010 at 3:25 PM by nerdyhearn, version 1

Comments

No comments yet.