jFormat ( v1.0 )
                                       - Amit Shejekan

What is jFormat?

As developers we design innumerous web forms with almost each field requiring some kind of format check. Common examples being email, phone number, zip codes etc.
jFormat is a reusable jQuery plugin aimed at making format checks easy.
Simply put a developer can inject various format checks onto form fields by just assigning appropriate class name to the field.
Please see the Demo for more details.

Download     


How to Use jFormat

Using jFormat is very easy
  1. Download the latest jFormat plugin
  2. Add the following lines to head section of the file, where you need format checker implemented <script type="text/javascript" src="jquery-1.4.3.js"></script> <script type="text/javascript" src="jFormat.js"></script>
  3. Add appropriate class name preceeded by "check_" to the fields that need format validation
    Example: <input type="text" name="user_email" class="check_email">
  4. Call the checkFormat() function whenever you need the format validation done
    Example:
    <script>
    function fnSubmit(){
    $(document).checkFormat();
    // Do Something
    }
    </script>
  5. Detailed Demo file is available in the download

How to Create Custom Formats

To create custom formats in jFormat
  1. Open jFormat.js in an editor
  2. Add the following variables
    1. var <classname>_regex = Regular Expression
    2. var <classname>_error_message = "Message to be displayed in case the value does not match the format"
  3. Use the class name as "check_<classname>" in the fields that needs format validation

Pre-Defined Formats

S.NoTypeClass NameFormat
1Emailcheck_emailabc@xyz.com
2URLcheck_urlhttp://www.google.com
3Integer Onlycheck_integerNNNN
4Floating Typecheck_floatNNNN.NN
5Alphabets Onlycheck_stringHello
6Phone Numbercheck_phone(NNN)NNN-NNNN
7Datecheck_dateNN-NN-NNNN
8Timecheck_timeNN:NN
9SSNcheck_ssnNNN-NN-NNNN
10Zip Codecheck_zipNNNNN
Legend: N = Digit

Demo

Name Alphabets Only
Email abc@xyz.com
URL http://www.google.com
Integers Only Integers Only
Float 123.23
Phone Number NNN-NNN-NNNN
Zip Code NNNNN
SSN NNN-NN-NNNN
Date NN-NN-NNNN
Time NN:NN