Show/Hide Toolbars

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

PHPrunner32x32     PHPRunner manual


Javascript API: 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 field required.

IsNumeric

A number.

IsPassword

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

IsEmail

Valid email address.

IsMoney

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

Two letter US state abbreviation. Examples: AK, AL, CA, MN.

IsSSN

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

IsCC

Valid credit card number.

IsTime

Any valid time format that match regional settings.

IsDate

Any valid date format that match regional settings.

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

A regular expression (regexp). Note that regexp validation overwrites the previous validation, if any.

 

Return value

 

No return value.

 

Example 1

 

Make all controls on the page required:

 

JavaScript OnLoad event

// Get all the controls for the table 'Cars'
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 regular expression validation to the control:

 

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

Method: removeValidation