- Regular Section
- To restrict the length of characters entered.
- To restrict the length of characters entered in a text box for more than one word.
- To restrict how a response begins
- To restrict how a response ends.
- Allow only a Numeric string of any length.
- To restrict the length of a numeric string to be specific length.
- To restrict the length of a numeric string to be between some numbers.
- To restrict the value of a numeric string to only be a positive integer.
- To restrict the length of a alphanumeric string to be specific number of characters.
- To restrict the length of a alphanumeric string to be between number of characters.
- To restrict the length of a alphanumeric string to be at least a given number of characters.
- To validate an email address.
- To validate number of words used.
- Repeat Section
- To restrict the length of characters entered.
- To restrict the length of characters entered in a text box for more than one word.
- To restrict how a response begins
- To restrict how a response ends.
- Allow only a Numeric string of any length.
- To restrict the length of a numeric string to be specific length.
- To restrict the length of a numeric string to be between some numbers.
- To restrict the value of a numeric string to only be a positive integer.
- To restrict the length of a alphanumeric string to be specific number of characters.
- To restrict the length of a alphanumeric string to be between number of characters.
- To restrict the length of a alphanumeric string to be at least a given number of characters.
- To validate an email address.
- To validate number of words used.
- Regular Section
Section name: client_id
-
-
To restrict the length of characters entered.
Example: First Name or Last Name (1 word between 3 and 50 characters in length)-
Question 1 Caption: Enter Client's first name
Question 1 Name: enter_client_first_nameif (!(/^\w+$/.test(tw.client_id.enter_client_first_name.value) && tw.client_id.enter_client_first_name.value.length.value >= 3 && tw.client_id.enter_client_first_name.value.length.value <= 50))
{
throw "Client's name must be between 3 and 50 characters long";
}
-
- To restrict the length of characters entered in a text box for more than one word (each word should be between 3 and 50 characters in length)
-
Question 1 Caption: Enter Client's first name and second name
Question 1 Name: enter_client_first_name_and_second_namvar words = tw.client_id.enter_client_first_name_and_second_name.value.split(" ");
for (var i = 0; i < words.length; i++)
{
if (!(words[i].length >= 3 && words[i].length <= 50))
{
throw "Client's First Name and Second name must each be between 3 and 50 characters long";
}
}
-
- Restrict how a response begins. Example: Begins with "PP"
-
Question 1 Caption: Enter Client's Identification number
Question 1 Name: enter_client_identification_numberif (!tw.client_id.enter_client_identification_number.value.startsWith("PP"))
{
throw "Client's Identification should start with PP";
}
-
- Restrict how a response ends. Example: Begins with "EE"
-
Question 1 Caption: Enter Client's Identification number
Question 1 Name: enter_client's_identification_numberif (!tw.client_id.enter_client_identification_number.value.endsWith("EE"))
{
throw "Client's Identification should end with EE";
}
-
- ONLY Allow a NUMERIC string. Could be of any length.
-
Question 1 Caption: Enter client's phone number
Question 1 Name: enter_client_phone_numberif (!/^\d+$/.test(tw.client_id.enter_client_phone_number.value))
{
throw "Only numbers are allowed.";
}
-
- Restrict the length of a numeric string. Example: Numeric String of length 10
- Question 1 Caption: Enter client's phone number
Question 1 Name: enter_client's_phone_numberif (isNaN(tw.client_id.enter_client_phone_number.value))
{
throw "Phone number should consist of only digits";
}
if (tw.client_id.enter_client_phone_number.value.length !== 10)
{
throw "Phone number should be 10 numbers long";
}
- Question 1 Caption: Enter client's phone number
- Restrict the length of a numeric string. Example: Numeric String of length 13 or 17
-
Question 1 Caption: Enter client's phone number
Question 1 Name: enter_client's_phone_numberif (isNaN(tw.client_id.enter_client_phone_number.value))
{
throw "Phone number should consist of only digits";
}
if (!(tw.client_id.enter_client_phone_number.value.length >= 13 && tw.client_id.enter_client_phone_number.length <= 17))
{
throw "Phone number should be between 13 and 17 numbers long";
}
-
- Restrict the value of a numeric string to only be a positive integer
-
Question 1 Caption: Enter cost of fertilizer
Question 1 Name: enter_cost_of_fertilizervar positiveInteger = parseInt(tw.client_id.enter_cost_of_fertilizer.value);
if (isNaN(positiveInteger) || positiveInteger <= 0)
{
throw "The cost of the fertilizer should be a positive number";
}
-
- Restrict the length of an alphanumeric string. Example: Alphanumeric String of length 7
-
Question 1 Caption: Enter passport number
Question 1 Name: enter_passport_numberif (tw.client_id.enter_passport_number.value.length !== 7)
{
throw "Passport number should be 7 characters long";
}
-
- Restrict the length of an alphanumeric string. Example: Alphanumeric String with between 5 to 7 characters
-
Question 1 Caption: Enter passport number
Question 1 Name: enter_passport_numberif (!(tw.client_id.enter_passport_number.value.length >= 5 && tw.client_id.enter_passport_number.value.length <= 7))
{
throw "Passport number should be between 5 and 7 characters long";
}
-
- Restrict the length of an alphanumeric string. Example: Alphanumeric String with atleast 7 characters
-
Question 1 Caption: Enter passport number
Question 1 Name: enter_passport_numberif (tw.client_id.enter_passport_number.value.length < 7)
{
throw "Passport number should be at least 7 characters long";
}
-
- To validate an email address. Example: nelly@gmail.com
-
function validateEmailAddress(emailString) {
// check for @ sign
var atSymbol = emailString.indexOf("@");
if(atSymbol < 1) return false;
var dot = emailString.indexOf(".");
if(dot <= atSymbol + 2) return false;
// check that the dot is not at the end
if (dot === emailString.length - 1) return false;
return true;
}
if(validateEmailAddress(tw.beneficiary_information.enter_email_address.value) === true){
// valid email
}
else{
throw "invalid email";
}
-
- To count number of words used.
-
function wordCount(str) {
return str.split(' ')
.filter(function ( n ) { return n !== '' ;})
.length;
}
if(wordCount(tw.beneficiary_information.name_of_the_beneficiary.value) > 10){
throw " total no. of words greater than 10";
}
-
-
-
- Repeat Section
Section name: demographic
-
-
To restrict the length of characters entered.
Example: First Name or Last Name (1 word between 3 and 50 characters in length)-
Question 1 Caption: Enter Client's first name
Question 1 Name: enter_client_first_nameif (!(^\w+$.test(tw.demographic.current.enter_client_first_name.value) && tw.demographic.current.enter_client_first_name.value.length >= 3 && tw.demographic.current.enter_client_first_name.value.length <= 50))
{
throw "Client's name must be between 3 and 50 characters long";
}
-
- To restrict the length of characters entered in a text box for more than one word (each word should be between 3 and 50 characters in length)
-
Question 1 Caption: Enter Client's first name and second name
Question 1 Name: enter_client_first_name_and_second_namvar words = tw.demographic.current.enter_client_first_name_and_second_name.value.split(" ");
for (var i = 0; i < words.length; i++)
{
if (!(words[i].length >= 3 && words[i].length <= 50))
{
throw "Client's First Name and Second name must each be between 3 and 50 characters long";
}
}
-
- Restrict how a response begins. Example: Begins with "PP"
-
Question 1 Caption: Enter Client's Identification number
Question 1 Name: enter_client_identification_numberif (!tw.demographic.current.enter_client_identification_number.value.startsWith("PP"))
{
throw "Client's Identification should start with PP";
}
-
- Restrict how a response ends. Example: Begins with "EE"
-
Question 1 Caption: Enter Client's Identification number
Question 1 Name: enter_client's_identification_numberif (!tw.demographic.current.enter_client_identification_number.value.endsWith("EE"))
{
throw "Client's Identification should end with EE";
}
-
- ONLY Allow a NUMERIC string. Could be of any length.
-
Question 1 Caption: Enter client's phone number
Question 1 Name: enter_client_phone_numberif (!/^\d+$/.test(tw.demographic.current.enter_client_phone_number.value))
{
throw "Only numbers are allowed.";
}
-
- Restrict the length of a numeric string. Example: Numeric String of length 10
-
Question 1 Caption: Enter client's phone number
Question 1 Name: enter_client's_phone_numberif (tw.demographic.current.enter_client_phone_number.value.length !== 10)
{
throw "Phone number should be 10 numbers long";
}
-
- Restrict the length of a numeric string. Example: Numeric String of length 13 or 17
-
Question 1 Caption: Enter client's phone number
Question 1 Name: enter_client's_phone_numberif (!(tw.demographic.current.enter_client_phone_number.value.length >= 13 && tw.Demographic.current.enter_client_phone_number.value.length <= 17))
{
throw "Phone number should be between 13 and 17 numbers long";
}
-
- Restrict the value of a numeric string to only be a positive integer
-
Question 1 Caption: Enter cost of fertilizer
Question 1 Name: enter_cost_of_fertilizervar positiveInteger = parseInt(tw.demographic.current.enter_cost_of_fertilizer.value);
if (isNaN(positiveInteger) || positiveInteger <= 0)
{
throw "The cost of the fertilizer should be a positive number";
}
-
- Restrict the length of an alphanumeric string. Example: Alphanumeric String of length 7
-
Question 1 Caption: Enter passport number
Question 1 Name: enter_passport_numberif (tw.Demographic.current.enter_passport_number.value.length !== 7)
{
throw "Passport number should be 7 characters long";
}
-
- Restrict the length of an alphanumeric string. Example: Alphanumeric String with between 5 to 7 characters
-
Question 1 Caption: Enter passport number
Question 1 Name: enter_passport_numberif (!(tw.Demographic.current.enter_passport_number.value.length >= 5 && tw.Demographic.current.enter_passport_number.value.length <= 7))
{
throw "Passport number should be between 5 and 7 characters long";
}
-
- Restrict the length of an alphanumeric string. Example: Alphanumeric String with atleast 7 characters
-
Question 1 Caption: Enter passport number
Question 1 Name: enter_passport_numberif (tw.Demographic.current.enter_passport_number.value.length < 7)
{
throw "Passport number should be atleast 7 characters long";
}
-
- Validate an email address. Example: taroworks@support.org
-
function validateEmailAddress(emailString) {
// check for @ sign
var atSymbol = emailString.indexOf("@");
if(atSymbol < 1) return false;
var dot = emailString.indexOf(".");
if(dot <= atSymbol + 2) return false;
// check that the dot is not at the end
if (dot === emailString.length - 1) return false;
return true;
}
if(validateEmailAddress(tw.beneficiary_information.enter_email_address.value) === true){
// valid email
}
else{
throw "invalid email";
}
-
- Count number of words used.
-
function wordCount(str) {
return str.split(' ')
.filter(function ( n ) { return n !== '' ;})
.length;
}
if(wordCount(tw.beneficiary_information.name_of_the_beneficiary.value) > 10){
throw " total no. of words greater than 10";
}
-
-
-
Comments
0 comments
Please sign in to leave a comment.