TRUE FORM VALIDATOR
TrueFormValidator is a set of javascript functions which frees web developers from having to write form validation code again and again . Most web developers know how time consuming and tedious it is to write client validation code for forms. Due to lack of proper debugging tools and IDE applications for Javascript, writing and fixing validation scripts can be a headache.
TrueFormValidator was created with just that purpose in mind. We at TrueLogic faced the same problem over the years and finally we have come up with our plugin script which saves us hours of coding and testing.
This script is a work in progress. Over time, it will be enhanced and improved according to usage and feedback received from its users.
Check the Demo
FEATURES
- Text Field Validations:
- Empty fields
- Numeric fields
- Date fields
- Spaces in text
- Field starting with an alphabet
- Field containing only alphabets
- Email field
- Dropdowns and Combo Boxes
- Customizable error messages
-
- Customizable date format
-
- Each field can be checked for multiple validations
HOW TO USE THE SCRIPT
1.
Download the latest version.
2.Add it to your page with the Script tag eg.
<SCRIPT LANGUAGE="JavaScript" src="tfv_1.3.js"></script>
Please do not hotlink it from this site, as it may change without warning in the near future.
3.In the form where you plan to use this tag, put the onsubmit clause in the <FORM tag like below:
<FORM name="myform" onsubmit="return tfv_validate(this)">
4.For fields which require validation, the tfv script scans the name of the field to decide which validation to run. The following tags in the field name are used. Note that the tags are case-sensitive
| Tag |
Used In |
Explanation |
| _v1_ |
Textboxes |
Validate for Empty field
Eg.<input name=firstname_v1_> will ensure firstname is never empty |
| _v2_ |
Textboxes |
Validate for Integer Value
Eg.<input name=ageofperson_v2_> will check that age is a valid integer above 0 |
| _v3_ |
Textboxes |
Validate for Floating Value
Eg.<input name=salary_v3_> will check for a valid currency value greater than 0.00 |
| _v4_ |
Textboxes |
Validate for Embedded Spaces
Eg.<input name=userid_v4_> will make sure userid does not have spaces in it |
| _v5_ |
Textboxes |
Validate for proper date
Eg.<input name=dtOfBirth_v5_> will make sure dtOfBirth has a valid date value |
| _v6_ |
Dropdown boxes |
Validate for Non-selected Combo Fields
Eg.<select name=countries_v6_> will make sure at least one value is selected in the list |
| _v7_ |
Textboxes |
Validate for starting value being an alphabet
Eg.<input name=myname_v7_> will make sure the first character entered is an alphabet (either upper or lowercase) |
| _v8_ |
Textboxes |
Validate for only alphabetical values
Eg.<input name=myname_v8_> will make sure the value contains only alphabets(either upper or lowercase) |
| _v9_ |
Textboxes |
Validate for email id
Eg.<input name=myemail_v9_> will validate that the email id is syntactically correct |
5.A field can contain multiple tags to do different validations eg. If an age textbox has to be checked to make sure that a value is entered and that the value is a valid age then the field can be declared as
<INPUT name="age_v1_v2_" >
6.The tags can be anywhere in the fieldname. It need not be always added as a suffix . The above field age_v1_v2_ will work even if its _v1_v2_age or age_v1_of_person_v2_
7.By default , each validation type will show a generic error message to the user and put cursor focus on the offending field. You can customize error messages for each field by adding elements to the global array tfv_error_msgs . This is an associative array which is set to empty by default. To add a custom error message for a field is very simple. Simply add an element to the array using the name of the field. For eg. to show a custom error message for the field age_v1_v2_ add this line in Javascript:
tfv_error_msgs['age_v1_v2_'] = "A valid age must be provided between 10 and 99";
7.For validating date fields the following customizations can be made:
| Field |
Explanation |
| CURRENT_DATE_FORMAT |
Default Value:DATE_FORMAT_MM_DD_YY
Valid Values:DATE_FORMAT_YYYY_MM_DD, DATE_FORMAT_YY_MM_DD, DATE_FORMAT_MM_DD_YYYY, DATE_FORMAT_DD_MM_YYYY, DATE_FORMAT_MM_DD_YY, DATE_FORMAT_DD_MM_YY
TFV provides 6 different date formats to choose from. To change the current format simply assign CURRENT_DATE_FORMAT to any of the date formats. Depending on this assignment, the values of the parameters below will change.
|
| YEAR_POS, MONTH_POS, DAY_POS |
Default Value:YEAR_POS=2, MONTH_POS=0, DAY_POS=1
Valid Values: YEAR_POS: 0 to 2, MONTH_POS: 0 to 2, DAY_POS: 0 to 2
Depending on the CURRENT_DATE_FORMAT chosen, the position of the year, month and day in the date string need to be changed. Positions start from 0, not 1.
So if CURRENT_DATE_FORMAT is set to DATE_FORMAT_YYYY_MM_DD, then YEAR_POS=0, MONTH_POS=1 and DAY_POS=2
|
| YEAR_FULL |
Default Value:false
Valid Values: true or false
Depending on the CURRENT_DATE_FORMAT chosen, this value will become true or false. Any format which uses the full year format YYYY will require YEAR_FULL=true otherwise a YY format will require YEAR_FULL=false;
|
| CURRENT_DATE_ERROR |
Default Value:Date must be in mm-dd-yy format
This is the default error message for a date field validation error. You can change this error message or if you are setting up a custom error message for the particular field then this field need not be changed.
|
VERSION HISTORY
Version:
1.3 released on 8th Oct,2009 size 11 Kb
Download it
- Fixed isAlphaStart() and isOnlyAlpha() functions to work with IE6
Version:
1.2 released on 8th Sept,2009 size 11 Kb
Download it
- Added validation for field values starting with an alphabet.
- Added validation for field values containing only alphabets.
- Added validation for email fields.
Version:
1.1 released on 3rd Aug,2009 size 8 Kb
Download it
- Fixed bug where validation checks were not working for password text fields.
Version:
1.0 released on 4th July,2009 size 8 Kb
Download it
LICENSE AND TERMS OF USE
This software is licensed under BSD License, which provides the user of this code, complete rights to use, modify and change the code as required, in free or commercial software, as long as the original copyright notice is preserved with the modified distribution.