Please enable JavaScript to view this site.

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

JavaScript API: Control object > addValidation()

Scroll Prev Next More

 

Adds validation to the control.

Syntax

ctrl.addValidation(validation_type);

Arguments

validation_type

one of the available validation types:

Validation type

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.

{
regex: "regular_expression",
message: "warning_message",
messagetype: "message_type"
}

A regular expression (regexp).

 

Note that regexp validation overwrites the previous validation, if there is any.

Return value

No return value.

Example 1

Make all controls on the page required using the JavaScript OnLoad event:

 

// Get all the controls for the 'Cars' table
var recCtrlsArr = Runner.controls.ControlManager.getAt('Cars');
// loop through all controls on the page making them all required
for(var i=0;i<recCtrlsArr.length;i++)
{
  var ctrl = recCtrlsArr[i];
   ctrl.addValidation("IsRequired");
}

Example 2

Add a regular expression validation to the control using the JavaScript OnLoad event:

 

var ctrl = Runner.getControl(pageid, 'Number');
ctrl.addValidation(/[0-9]/);
ctrl.customValidationFailedMessages[ "RegExp" ] = {
   message: "The field should be a number from 0 to 9",
   messageType: "Text"
};

See also:

JavaScript API: Control object > getControl()

JavaScript API: Control object > validate()

JavaScript API: Control object > validateAs()

JavaScript API: Control object > removeValidation()

JavaScript API: Control object > invalid()

"Edit as" settings : Validation types

Events: JavaScript OnLoad

JavaScript API: Control object

JavaScript API