Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input mask for an ip address? 1

Status
Not open for further replies.

strebor

Technical User
Nov 24, 2004
66
US
I would like to format an input mask for entering ip addresses... 255.255.255.0, or 136.14.122.1 or 14.122.2.133. If the user just puts 2 digits in one of the octets, the mask would format the string correctly. Any ideas? It could be that masks won't do it, and that a better way would be to check what was entered and either format it correctly or request the user to re-enter.

 
You could add something simple like this to the change event of that txt field. This inserts a 'dot' after each three chars keyed (up to 11 chars)
'---
Dim strDot as string
strDot = ""
Select Case Len(txtNewValue2.Text)
Case 3, 7, 11
strDot = "."
End Select
txtNewValue2.Text = txtNewValue2.Text & strDot
'---

If there isn't standard for the break between chars then I would just simply use a split function or something like that on the AfterUpdate event to check what the user entered. You could do something like this to validate the lengths of data between the dots:

values = split(txtNewValue2.text, ".")
For x = Lbound(values) to Ubound(values)
If Len(values(x)) < 1
'(or 2 or whatever)
'then do something, warn user
End if
Next x
 
This gave me a good idea. I think I will limit the entry of the field to 15 char... then, make sure that there are no more than 3 chars between the dots and that there are no leading zeros in each of the four sets of numbers. I will try and post the results later.
 
Becareful while checking for leading zeros. If they're entering a subnet mask, there will always be a zero (to the best of my knowledge)

-------------------------
Just call me Captain Awesome.
 
Point taken... in this application they won't be entering subnet masks, but I will account for that anyway. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top