bluelinecity.com

Foul

Foul is a JavaScript based, form validation language. If you hate all the rigamarole you have to go through just to check a simple web form, then this script is what you need.

I’m a veteran when it comes to form validation. I know first hand how much of a pain it is. This script makes form validation stupidly easy and still allows for that tweaking that programmers are always looking for.

Foul contains a full language parsing engine which compiles advanced conditions and tests for the fields of a form. The language makes building tests as easy as saying what you want. The tests include, blank fields, numbers, phone numbers, credit cards, urls, zip codes, states, emails, social security numbers ranges, lengths, dates, file types and much more. Foul also contains an auto-formatting feature which fixes the data before it’s set.

http://bluelinecity.com/images/zip_icon.gif Download Foul 1.7.2

Here’s a quick example of how much easier Foul makes form validation…

BEFORE FOUL ( 2,072 Bytes 63 Lines )

function validate(frm) {
if ( frm.elements["Name"].value == ” ) {
alert( "Please enter your name." );
frm.elements["Name"].focus();
return false;
}
if ( frm.elements["Title"].value == ” ) {
alert( "Please enter your title." );
frm.elements["Title"].focus();
return false;
}
if ( frm.elements["Organization"].value == ” ) {
alert( "Please enter the name of your company." );
frm.elements["Organization"].focus();
return false;
}
if ( frm.elements["Address"].value == ” ) {
alert( "Please enter your address." );
frm.elements["Address"].focus();
return false;
}
if ( frm.elements["City"].value == ” ) {
alert( "Please enter your city." );
frm.elements["City"].focus();
return false;
}
if ( frm.elements["State or Province"].selectedIndex == 0 ) {
alert( "Please select your state or province.");
frm.elements["State or Province"].focus();
return false;
}
if ( frm.elements["Postal or Zip Code"].value == ” ) {
alert( "Please enter your postal or zip code.");
frm.elements["Postal or Zip Code"].focus();
return false;
}
if ( frm.elements["Country"].value == ” ) {
alert( "Please enter your country." );
frm.elements["Country"].focus();
return false;
}
// Check the Email field to see if any characters were entered
if ( frm.elements["Email Address"].value == ” ) {
alert( "Please enter an email address." );
frm.elements["Email Address"].focus();
return false;
}
// Now check Email field for the "@" symbol
if (!/^.+\@..+\..+/.test(frm.elements["Email Address"].value)) {
alert( "Please enter a valid email address." );
frm.elements["Email Address"].focus()
return false;
}
if ( frm.elements["Phone Number"].value == ” ) {
alert( "Please enter your phone number." );
frm.elements["Phone Number"].focus();
return false;
}
if ( frm.elements["Message"].value == ” ) {
alert( "Please enter your message, comments, or questions." );
frm.elements["Message"].focus();
return false;
}
}

AFTER FOUL ( 435 Bytes 11 Lines )

foul.when("~Name~");
foul.when("~Title~");
foul.when("~Organization~");
foul.when("~Address~");
foul.when("~City~");
foul.when("~State or Province~");
foul.when("~Postal or Zip Code~");
foul.when("~Country~");
foul.when("~Email Address~");
foul.when("~Email Address~ is not email");
foul.when("~Phone Number~");
foul.when("~Message~");

Features

  • Fast and simple installation
  • Natural language-like programming
  • Support for compound tests using ‘and’ and ‘or’ and even test grouping using parenthesis
  • Tests for blanks, spaces, null, numbers, length, ranges, emails, credit cards and more
  • Formatting function that formats fields before submission
  • Easy to modify or add new native Foul tests
  • Can interact with user as they move from field to field
  • Supports any standard form field. (except for file and multiple-select boxes)
  • Formats phone numbers, decimals, credit card numbers and more
  • Customizable error messages
  • Maximum portability from form to form
  • Build and combine validation sets quickly
  • Completely FREE

Future of Foul

I’m going to continue working on native Foul tests going beyond basic tests and into things such as zip codes, addresses, multi-field controls. I would like to also provide a way for people to create new tests from a set of tests so they can develop their own dialect of foul for their forms. For example, say you have a form that has a special id that is required, can’t contain spaces and character length must range between 15 and 19 letters. You could create a new test named ’special-id’ and alias it to this command ‘~f~ is null or ~f~ has spaces or ~f~ is not length between 15 19′ extending Foul in an inline fashion without creating a native Foul test.

One Response to “Foul”

  1. New version of Foul (foul.js) coming soon? - Ramblings of a Serial Entrepreneur Says:

    [...] you don’t know about Foul, it is a javascript validation tool that is a very easy way to validate basic forms. It’s [...]

Leave a Reply