Validation function use cases
Common use cases and code samples of validation function.
Validate if a product is eligible for delivery to a specific address
The following code sample validates whether the value in the Address__c field is included in a given array.
Validate aged invoices
The following code sample validates whether the date in the Due_Date__c field is more than 90 days ahead of the current date, which indicates the invoice aging is greater than 90 days.
Validate currency format
The following code sample validates whether the value in the AcceptedCurrency__c field matches the regular expression for the USD currency format.
Validate URL protocol
The following code sample validates whether the value in the Source__c field is a valid URL.
Validate field entry
The following code sample validates whether the BillingState__c field is specified when the value in the Country__c field is United States.
Validate social security number format
The following code sample validates whether the value in the SSN__c field is a valid social security number.
Validate positive values
The following code sample validates whether the value in the Credit_Limit__c field equals or is greater than 0.
Validate if a field is an email address
The following code sample validates whether the value in the Email__c field of the default__users custom object is in the format of an email address.
Validate field content length
The following code sample validates whether the value in the Name field of an account is equal to or less than 10 characters.
Validate if a field contains special characters
The following code sample validates whether the value in the Comments field of an invoice contains any special characters.