Example Business Rules for Text fields.

2 minute read time.
Below are some code examples showing how Business Rules can be implemented on Text fields using the onChange and Validation script options within a screen.
The examples shown are:
  1. The field may only contain letters and numbers
  2. The field may only contain uppercase or lowercase letters.
  3. The field may only contain numeric characters.
  4. The first character must be in uppercase.
  5. Forbidden character(s) used in String
The examples assume that the text field is called 'comp_customfield'.

1) The Field may only contain Letters and Numbers

onChange Example

var strRuleMessage = 'Field may only contain Letters and Numbers';
re =/[^A-Za-z0-9]/;
r = this.value.match(re);
if (r)
{
window.alert(strRuleMessage);
}

Validation Example

var strRuleMessage = "Field may only contain Letters and Numbers";
var strFieldData = Values("comp_customfield");
re =/[^A-Za-z0-9]/;
r = strFieldData.match(re);
if (r)
{
Valid = false;
ErrorStr = strRuleMessage;
}

2) The field may only contain uppercase or lowercase letters.


onChange Example

var strRuleMessage = 'The field may only contain uppercase or lowercase letters';
re =/[^A-Za-z]/;
r = this.value.match(re);
if (r)
{
window.alert(strRuleMessage);
}

Validation Example

var strRuleMessage = 'The field may only contain uppercase or lowercase letters';
var strFieldData = Values("comp_customfield");
re =/[^A-Za-z]/;
r = strFieldData.match(re);
if (r)
{
Valid = false;
ErrorStr = strRuleMessage;
}


3) The field may only contain numeric characters.

onChange Example


var strRuleMessage = 'The field may only contain numeric characters';
re =/[^0-9]/;
r = this.value.match(re);
if (r)
{
window.alert(strRuleMessage);
}

Validation Example

var strRuleMessage = 'The field may only contain numeric characters';
var strFieldData = Values("comp_customfield");
re =/[^0-9]/;
r = strFieldData.match(re);
if (r)
{
Valid = false;
ErrorStr = strRuleMessage;
}

4) The first character must be in uppercase.

onChange Example

var strRuleMessage = 'The first character must be in uppercase.';
var strData = this.value;
var strCorrectCheck = strData.substr(0,1).toUpperCase()+strData.substr(1).toLowerCase();
if (strData !=strCorrectCheck)
{
window.alert(strRuleMessage);
}

Validation Example

var strRuleMessage = 'The first character must be in uppercase.';
var strData = Values("comp_customfield");;
var strCorrectCheck = strData.substr(0,1).toUpperCase()+strData.substr(1).toLowerCase();
if (strData !=strCorrectCheck)
{
Valid = false;
ErrorStr = strRuleMessage;
}

5) Forbidden character(s) used in String

The forbidden character in this example are "£", "$", and "%".

onChange Example


var strRuleMessage = 'Forbidden character(s) used in String';
re =/[£$%]/;
r = this.value.match(re);
if (r)
{
window.alert(strRuleMessage);
}

Validation Example

var strRuleMessage = 'Forbidden character(s) used in String';
var strFieldData = Values("comp_customfield");
re =/[£$%]/;
r = strFieldData.match(re);
if (r)
{
Valid = false;
ErrorStr = strRuleMessage;
}