Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > JavaScript API > Control object > Methods

JavaScript API: Control object > validateAs()

Scroll Prev Next More

 

Validates the control value for a certain validation type. The control is not marked as unvalidated.

Syntax

var vRes = ctrl.validateAs(validation_type);

Arguments

validation_type

one of the available validation types:

Validation constant

Description

IsRequired

Makes the field required.

IsNumeric

A number.

IsPassword

The password cannot be blank, cannot be 'Password' and should be at least 4 characters long.

IsEmail

A valid email address.

IsMoney

A numeric value. Decimal point is allowed. Examples: 13, 24.95.

IsZipcode

Five or ten digit number. Valid formats: 12345, 12345-6789 or 123456789.

IsPhonenumber

Numbers, spaces, hyphens, and parentheses are allowed. Examples: (123) 456-7890, 123 456 7890, 123 4567.

IsState

A two-letter US state abbreviation. Examples: AK, AL, CA, MN.

IsSSN

A nine-digit US social security number. Valid formats: 123-45-6789 or 123 45 6789.

IsCC

A valid credit card number.

IsTime

Any valid time format that matches regional settings.

IsDate

Any valid date format that matches regional settings.

Return value

Returns true or a validation error.

Example

Validate the control value for the "IsRequired" validation using the JavaScript OnLoad event:

 

var ctrl = Runner.getControl(pageid, 'make');
Runner.validation.control = ctrl;
var vRes = ctrl.validateAs("IsRequired");

See also:

JavaScript API: Control object > getControl()

JavaScript API: Control object > addValidation()

JavaScript API: Control object > removeValidation()

JavaScript API: Control object > validate()

JavaScript API: Control object > invalid()

"Edit as" settings: Validation types

Events: JavaScript OnLoad

JavaScript API: Control object

JavaScript API