You are on page 1of 2

COMMUNITY WIKI : LCV Examples

This page last changed on Oct 21, 2011 by rpinion.

This page will provide sample validations using LCV, the Lightweight Client-side Validation pattern. Seethe main LCV page for the LCV code and instructions on how to implement it. LCV validates any control that has an lcv, lcv_custom, or lcv_table classname. If it finds that "toplevel" classname, then it looks at the other pre-defined lcv classnames and responds accordingly. If a control has one of the "required" validators, and that validator fails, then none of the other validators for that ccontrol is tested. The samples below can serve as a reference list, of sorts, to the most common validation needs.

Validating regular text fields and selects


Input is required

lcv lcv_input_required Error message: Value is required


Input is required with Label-based error message

lcv lcv_input_required lcv_label_First_Name Error message: First Name is required Notes: -Labels must contain underscores for spaces -If a valid lcv_label class is not found, the default word "Value" is used instead. This applies to all validators, except when a custom error message is created
Input is required with custom error message

lcv lcv_input_required lcv_errorMessage_Please_enter_a_first_name Error message: Please enter a first name


Input must be numeric

lcv lcv_isNumeric Error message: Value must be numeric


Input not equal to a value

lcv lcv_input_notEqualToVal lcv_input_notEqualToVal_val_-1 Error message: Value must not be -1


Input not equal to a Javascript variable

lcv lcv_input_notEqualToVar lcv_input_notEqualToVar_var_DepartureCity Error: Value must not be New York City (assuming DepartureCity's current value is "New York City")

Document generated by Confluence on Nov 14, 2011 14:41

Page 1

Input less than or equal to the value in another field

lcv lcv_input_lessThanEqualToControl lcv_input_lessThanEqualToControl_id_InputText2 Error: Value must be less than or equal to 48 (assuming InputText2's current value is 48)
Input is required when a particular radio button is selected

lcv lcv_input_radioRequiredWhenRadioEqualVal lcv_input_radioRequiredWhenRadioEqualVal_val_Yes lcv_input_radioRequiredWhenRadioEqualVal_name_tw#local#likesIceCream Error: Value is required. (It is suggested you include a custom error message for this validator.)
Input with multiple custom error messages

lcv lcv_input_required lcv_input_required_errorMessage_Birth_year_is_required lcv_input_isNumeric lcv_input_greaterThanVal lcv_input_greaterThanEqualToVal_val_1900 lcv_errorMessage_Birth_year_must_be_a_four_digit_year_after_1900 Error (if empty): Birth year is required Error (if non-numeric): Birth year must be a four digit year after 1900 Error (if earlier than 1900): Birth year must be a four digit year after 1900 Note: the "lcv_errorMessage" (if provided) is the "catch-all" error that will be applied to both the isNumeric and greaterThanValEqualTo validators since they do not have rule-specific error messages.
Input with default error message based on label

lcv lcv_input_required lcv_input_isNumeric lcv_label_Birth_year Error message (if empty): Birth year is required Error message (if non-numeirc): Birth year must be numeric

Document generated by Confluence on Nov 14, 2011 14:41

Page 2

You might also like