Manage Learn to apply best practices and optimize your operations.

Reusable field validation function

Rather than using input validation formulas, or even a separate LotusScript validation code for each field, this function provides a reusable, easily-maintained validation method.

View member feedback to this tip.

Rather than using input validation formulas, or even a separate LotusScript validation code for each field, this function provides a reusable, easily-maintained validation method. Also, since actual field names are often not 'user-friendly' this function returns friendly field labels when prompting the user for input.

Calling the function:  QuerySave event
If not ValidateFields(source) then 
exit sub 
end if

The functions:
Function ValidateFields(source as 
notesuidocument)as integer 
dim requiredfields as variant 
dim requiredlabels As variant 
dim fieldlist as string 
dim fieldlabels as string 
dim badfields as string 
dim errortext as string 
dim firstfield as string


'create two strings, one for field names
 and one for the associated user-
friendly field labels 
'you need only to modify these strings to 
add, remove, or modify the fields to 
be validated 
fieldlist = "fname;lname;homephone;
fieldlabels = "First Name; Last Name; 
Home Phone; Cell Phone; Birthday"

'call a separate string-handling function 
to convert the strings to arrays 
requiredfields = explodestring(fieldlist,";") 
requiredlabels = explodestring(fieldlabels,";")
dim i,z as integer
forall fields in requiredfields
tmpval = source.fieldgettext(requiredfields(i))
if tmpval = "" then
if badfields = "" then
'build a string of friendly field labels for the 
validation error 
badfields = requiredlabels(i) 
'grab the actual field where we will place the
 cursor if there is an error 
firstfield = requiredfields(i) 
else badfields = badfields & Chr(13) & 
end if 
end if
end forall

'if any field raises an error, return a validation 
error listing fields to be 
if badfields <> "" then 
dim warning as string 
warning = "The following required fields must 
be completed before you can save 
this record:" & Chr(13) & Chr(13) & badfields
call source.gotofield(firstfield)
end if
end function

Note: The following function is a modified 
version of a tip that has been 
entered by various persons at several tips sites. 
Function ExplodeString (txtstring as string, 
delimiter as string) as variant
dim reqfields() as string
dim fieldname as string
dim pos as integer
dim i as integer

pos=instr(txtstring, delimiter)

redim reqfields(i)
while pos > 0
fieldname = Left(txtstring, pos-1)
redim preserve reqfields(i)
txtstring=Right(txtstring, Len(txtstring)-pos)
'add the last remaining value of txtstring 
to the array
redim preserve reqfields(i)
reqfields(i) = txtstring
explodestring = reqfields
end function


Many thanks to William Key and the SearchDomino team for bringing us this very valuable and useful tip.

In a large scale application development, using densely populated forms, this generic validation routine helps save a lot of time and efforts. It completely eliminates the chore of coding repetitive validation messages and prompts. The author has done an excellent job of providing a neat and error-free code, not only for the main function but also for other called functions.

A job well-done !

—Rajan M.


This is a great tip. I have used it twice already with excellent results!

—Beatriz R.

Do you have comments on this tip? Let us know.

This tip was submitted to the tip exchange by member William Key. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Dig Deeper on LotusScript

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...