Phone Number Validation

Everybody likes to input their phone numbers in a different way, right? This will take any format and convert it

immediately to a (123) 456-7890 format. I would recommend that you also add the line source.gototop on your querysave event to ensure the script is processed before the file is saved.


Sub Exiting(Source As Field)
Dim ws As New notesuiworkspace
Dim doc As notesuidocument
Set doc = ws.currentdocument
Dim phone As String, message As String
Dim num As Double
Dim fieldname As String

fieldname = "emp_phone"  'Place the name of the field here

phone = doc.fieldgettext(fieldname)
On Error Goto clear_field
phone = Trim$(phone)
If phone = "" Then
Call doc.fieldsettext(fieldname,"")
Exit Sub
End If
If Cstr(phone) Like "[(]???[)][ ]???[-]????" Then
phone = Mid$(phone,2,3) & Mid$(phone,7,3) & Right(phone,4)
Goto correct
End If
If Cstr(phone) Like "???[-]???[-]????" Then
phone = Left$(phone,3) & Mid$(phone,5,3) & Right(phone,4)
Goto correct
End If
If Len(phone) = 10 Then
Goto correct
Else
message = "You must enter the phone number as 123-456-7890 or 1234567890."
Messagebox  message, 16, "Incorrect Entry"
Call doc.GotoField(fieldname )
Exit Sub
End If
correct:
num = Cdbl(phone)
phone =  "(" & Left$(phone,3) & ") " & Mid$(phone,4,3) & "-" & Right(phone,4)
Call doc.fieldsettext(fieldname,phone)
Exit Sub clear_field: message = "You must enter the phone number as 123-456-7890 or 1234567890." Messagebox message, 16, "Incorrect Entry" Call doc.gotofield(fieldname) Exit Sub End Sub
This was first published in November 2000

Dig deeper on Lotus Notes Domino Administration Tools

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.uk

Close