|
-
Mar 25th, 2007, 02:48 PM
#1
Thread Starter
Lively Member
[RESOLVED] phone number
this codes validates phone numbers so if the user inputs the number in as 01159313481 or 0115 9313481 it accepts it and anything else it dosnt. the only problem i have is that it dosnt check if the space is in the right place, for example the user can put in 01159 313481 and it is accepted, any ideas?
Private Sub TextBox4_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
TextBox4.Text = Trim(TextBox4.Text)
If TextBox4.TextLength = 11 Then
Dim position
position = InStr(5, TextBox4.Text, " ")
If position = 0 Then
spacedpost = TextBox4.Text
TextBox4.Text = Mid(spacedpost, 1, 4) & " " & Mid(spacedpost, 5, Len(spacedpost) - 4)
Else: MsgBox TextBox4.Text & " is not a valid mobile number. Please enter a valid 12 digit mobile number."
TextBox4.Text = ""
End If
Exit Sub
ElseIf TextBox4.TextLength = 12 Then
Dim position1
position1 = InStr(5, TextBox4.Text, " ")
If position1 = 0 Then
MsgBox TextBox4.Text & " is not a valid mobile number. Please enter a valid 12 digit mobile number."
TextBox4.Text = ""
ElseIf position = 1 Then
End If
Exit Sub
Else: MsgBox TextBox4.Text & " is not a valid mobile number. Please enter a valid 12 digit mobile number."
TextBox4.Text = ""
TextBox4.SetFocus
Cancel = True
End If
End Sub
any help is much appreciated
Joe
-
Mar 25th, 2007, 02:51 PM
#2
Re: phone number
I say remove all spaces, check for valid length, then reformat in the correct space format and be done.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 25th, 2007, 02:53 PM
#3
Thread Starter
Lively Member
Re: phone number
how would i remove all the spaces? i also want to check that it starts with a 0. how would i do this?
-
Mar 25th, 2007, 02:54 PM
#4
Re: phone number
Use the Replace function passing the string, what to look for (space) and replace with a nullstring.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 25th, 2007, 02:55 PM
#5
Thread Starter
Lively Member
Re: phone number
and checking that it starts with a 0??
-
Mar 25th, 2007, 02:57 PM
#6
Re: phone number
If that is a validation criteria, then yes, plus any other criteria that will make the format valid.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 25th, 2007, 03:06 PM
#7
Thread Starter
Lively Member
Re: phone number
i now have this but i get an error, object rquired, do you know what i am doing wrong
vb Code:
Private Sub TextBox4_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
spacedpost = Replace(TextBox4.Text, " ", "")
If spacedpost.TextLength = 11 Then
TextBox4.Text = Mid(spacedpost, 1, 4) & " " & Mid(spacedpost, 5, Len(spacedpost) - 4)
Else
MsgBox TextBox4.Text & " is not a valid mobile number. Please enter a valid 12 digit mobile number."
TextBox4.Text = ""
TextBox4.SetFocus
Cancel = True
End If
End Sub
what criteria would i have to use to check that the number began with a 0?/
thanks
Last edited by RobDog888; Mar 25th, 2007 at 03:13 PM.
Reason: Added [highlight] tags
-
Mar 25th, 2007, 03:17 PM
#8
Re: phone number
You could use the Instr to look at position 1.
Ps, I edited your post and reformatted the code with highligh=vb code tags for easier reading.
vb Code:
Private Sub TextBox4_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim strPhone As String
strPhone = Replace(TextBox4.Text, " ", "")
If Len(strPhone) = 11 And Instr(1, strPhone, "0") = 1 Then
strPhone = Mid(strPhone, 1, 4) & " " & Mid(strPhone, 5, Len(strPhone) - 4)
Text4.Text = strPhone
Else
MsgBox TextBox4.Text & " is not a valid mobile number. Please enter a valid 12 digit mobile number."
TextBox4.Text = ""
TextBox4.SetFocus
Cancel = True
End If
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 25th, 2007, 03:22 PM
#9
Thread Starter
Lively Member
Re: phone number
if i put in 01159313481 i get a runtime error 424: object rquired, any idea why?
-
Mar 25th, 2007, 03:31 PM
#10
Re: phone number
What line of code? Diid you use what I posted?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 25th, 2007, 03:38 PM
#11
Thread Starter
Lively Member
Re: phone number
i used exactly what you posted and it gave me that error, it highlighted this line
Text4.Text = strPhone
in the first part of the if statement. the rest of it works though.
-
Mar 25th, 2007, 03:41 PM
#12
Re: phone number
Arrg, my VB 6 brain is taking over lol.
Change it to TextBox4.Text and not Text4.Text.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 25th, 2007, 03:45 PM
#13
Thread Starter
Lively Member
Re: phone number
yep that works. brilliant, thankyou very much for all your help. joe
-
Mar 25th, 2007, 03:46 PM
#14
Re: [RESOLVED] phone number
No prob. Glad to help.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|