Validation Methods Library

When a validation method is created, there are two types of methods created: a "validate" and an "is" method. The "validate" methods are used to bind validation to a form field. "Validate" methods on need to be run once and are normally called at initialization time. The "is" methods are used to determine if an error occurred. If an error occurred, then the "is" method will return false, otherwise it will return true if no error occurred. The "validate" methods will handle throwing the errors for you automatically. The following descriptions for the validation methods assume you know the difference between the two types of methods. Both "validate" and "is" methods share the same arguments

In the properties and methods below, obj is an abbreviation for the object name you specified when you called the qForm constructor. fieldName signifies the form field element that you want to perform the action on. Arguments in bracket ("[ ]") are optional.

Methods

obj.fieldName.validateAlpha()
obj.fieldName.isAlpha()
The isAlpha method tests the selected form object to make sure that it contains an alpha string (contains only characters A-Z and a-z.) If the value is not an alpha string, then an error is generated.
obj.fieldName.validateAlphaNumeric()
obj.fieldName.isAlphaNumeric()
The isAlphaNumeric method tests the selected form object to make sure that it contains an alphanumeric string (contains only characters A-Z and a-z or numbers 0-9.) If the value is not alphanumeric, then an error is generated.
obj.fieldName.validateCreditCard()
obj.fieldName.isCreditCard()
The isCreditCard method will check to make sure the selected form element's value passes a MOD10 check. It does this by stripping out all non-numeric characters and running a MOD10 check on the remaining numeric characters. If the value remainder of the MOD10 check does not return 0, then an error is generated.
obj.fieldName.validateDate([string mask])
obj.fieldName.isDate([string mask])
The isDate method checks the selected form object to make sure the value contained appears to be a valid date. If the value does not appear to be a valid date, then an error is generated.

The mask argument is an optional argument that defaults to "mm/dd/yyyy". The mask is created using a combination of the character sets "mm", "dd" and "yyyy" (or yy).

For example, to specify a European-style date format, you can specify the mask as "dd-mm-yyyy" or "dd/mm/yyyy".

obj.fieldName.validateDifferent(string field)
obj.fieldName.isDifferent(string field)
The isDifferent() method will compare the selected form object to the form element specified in the field argument.

The field argument is required and must be equal to the name of another qForms field object. If the selected field object and the specified field element are identical, then the isDifferent() method will generate an error.

obj.fieldName.validateEmail()
obj.fieldName.isEmail()
The isEmail method will check to make sure the selected form element's value contains a valid e-mail address. It does this by make sure that the e-mail address contains certain required characters (i.e. the @ symbol and at least one period after the @ symbol.) If the field does not contain an e-mail address, then an error is generated.
obj.fieldName.validateFormat(string mask, [string type])
obj.fieldName.isFormat(string mask, [string type])
The format method allows you to define a basic format that the current field must be in. The mask can defined in several ways. You can either use a default mask, or create your own mask. Custom masks are created by using "X"'s to define valid data types. Wherever an "x" is placed, a valid character type must be present. Valid data types are defined using the optional "type" argument.

The type argument is an optional parameter that defaults to "numeric." Valid values for the "type" argument are "numeric", "alpha" and "alphanumeric". When using the "numeric" type, then a valid number (0-9) must be filled in for each "X" in the mask. When using the "alpha" type, then an alpha character (A-Za-z) must exist for each "X" in the mask. When using the "alphanumeric" type, either a valid number or alpha character (0-9A-Za-z) needs to be present for each "X" in the mask.

The mask argument can be any custom string, or one of the following predefined masks:

SSN
Makes sure that a 9-digit number in the format "xxx-xx-xxxx" is entered.

Phone (or Phone1)
Makes sure that a 10-digit number in the format "(xxx) xxx-xxxx" is entered.

Phone2
Makes sure that a 10-digit number in the format "xxx-xxx-xxxx" is entered.

Phone3
Makes sure that a 10-digit number in the format "xxx/xxx-xxxx" is entered.

Phone7
Makes sure that a 7-digit number in the format "xxx-xxxx" is entered.

Zip
Makes sure either a 5 or 9-digit number is entered in either the format "xxxxx" or "xxxxx-xxxx".

Zip5
Makes sure a 5-digit number is entered in the format "xxxxx".

Zip9
Makes sure a 9-digit number is entered in the format "xxxxx-xxxx".

obj.fieldName.validateInteger()
obj.fieldName.isInteger()
The isInteger method tests the selected form object to make sure that it contains a numeric value. It does this by passing the string into the parseInt() function. If the value is not numeric, then an error is generated.
obj.fieldName.validateLength([int length], [string type])
obj.fieldName.isLength([int length], [string type])
The isLength method will check to make sure the selected form element's length is equal to its length argument value. It does this by stripping out all non-valid characters and comparing the length of the value to the value of the length argument. If the lengths do not match, then an error is generated.

The length argument is an optional argument, which specifies the length that a valid phone number should be. The default value is 10.

The type argument is an optional parameter that defaults to "numeric." Valid values for the "type" argument are "numeric", "alpha" and "alphanumeric". Any character that does not match the type specified will be removed when comparing the lengths.

obj.fieldName.validateLengthGT(int length)
obj.fieldName.isLengthGT(int length)
The isLengthGT method will check to make sure the selected field's value is greater than in length than the specified length argument value. If the field value's length is less than the length arguement an error is thrown.
obj.fieldName.validateLengthLT(int length)
obj.fieldName.isLengthLT(int length)
The isLengthLT method will check to make sure the selected field's value is less than in length than the specified length argument value. If the field value's length is greater than the length arguement an error is thrown.
obj.fieldName.validateNotEmpty()
obj.fieldName.isNotEmpty()
The isNotEmpty method will check to make sure the selected form element's value is not blank. It does this by trimming all whitespace and checking to make sure the length of the string is not equal to zero. If the field is blank, then an error is generated.
obj.fieldName.validateNotNull()
obj.fieldName.isNotNull()
The isNotNull method will check to make length of the specified string is not equal to zero. If the string length has a length of zero, then an error is generated.
NOTE: This validation method will run regardless of value of the field's "required" property.
obj.fieldName.validateNumeric()
obj.fieldName.isNumeric()
The isNumeric method tests the selected form object to make sure that it contains a numeric value. It does this by passing the string into the parseFloat() function. If the value is not numeric, then an error is generated.
obj.fieldName.validatePassword([string field], [int min], [int max])
obj.fieldName.isPassword([string field], [int min], [int max])
The isPassword method is used to determine whether the selected form element is a password. It does this by comparing the selected form element (when provided) to the value of the field argument and make sure the length of the password is between the minimum and maximum number of characters allowed. If any condition fails, an error is generated.

The field argument is an optional field. If set to null, then the selected element's value is not compared to another field. If a field is specified, then the selected field object and the specified field element must match in order for the isPassword() method to not return an error.

The min argument is the minimum number of characters the password must be. The default value for this is 1.

The max argument is the maximum number of characters the password must be. The default value is 255.

obj.fieldName.validatePhoneNumber([int length])
obj.fieldName.isPhoneNumber([int length])
The isPhoneNumber method will check to make sure the selected form element's length is equal to its length argument value. It does this by stripping out all non-numeric characters and comparing the length of the value to the value of the length argument. If the lengths do not match, then an error is generated.

The length argument is an optional argument, which specifies the length that a valid phone number should be. The default value is 10-which is the correct number of digits for a US phone number. (Area Code + 7-digit phone number.)

obj.fieldName.validateRange(int min, int max)
obj.fieldName.isRange(int min, int max)
The isRange method will check to make sure the selected form element's value is between the minimum and maximum numbers allowed. If the value does not fall between the minimum and maximum values, then an error is generated.

The min argument is the minimum number of the range. This attribute is required.

The max argument is the maximum number of the range. This attribute is required.

obj.fieldName.validateSame(string field)
obj.fieldName.isSame(string field)
The isSame() method will compare the selected form object to the form element specified in the field argument.

The field argument is required and must be equal to the name of another qForms field object. If the selected field object and the specified field element are different, then the isSame() method will generate an error.

obj.fieldName.validateSSN()
obj.fieldName.isSSN()
The isSSN method will check to make sure the selected form element's length contains 9 numeric characters. It does this by stripping out all non-numeric characters and making sure the length of the string is equal to 9. If the length is not 9, then an error is generated.
obj.fieldName.validateState()
obj.fieldName.isState()
The isState method will check to make sure the selected form element's value is a valid 2-digit US postal abbreviation (example "OH" is the 2-digit abbreviation for "Ohio.") If the value is not a valid 2-digit abbreviation, then an error is generated.
obj.fieldName.validateZipCode()
obj.fieldName.isZipCode()
The isZipCode method will check to make sure the selected form element contains either a 5 or 9-digit numeric number. If the number of numeric characters is not equal to either 5 or 9, then an error is generated.

Note: All validation methods automatically are given argument of "errorMsg". This argument is assigned as the last argument for the method and is used to provided a custom error message instead of using the default error message. For more information, please see "Custom Error Messages".

[< Back] [Index] [Next >]