Manage Learn to apply best practices and optimize your operations.

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

Dig Deeper on Lotus Notes Domino Administration Tools

SearchWindowsServer

Search400

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury

SearchDataCenter

SearchContentManagement

Close