Hi,

I have an Intranet page where users enter IP addresses. I
have one field for each of the four octects which comprise
an IP address. My problem is that I am getting many
invalid entries like 165.131.01.09 instead of
165.131.1.9 ... basically I am looking for an event
handler to strip any leading "0" from entries (e.g. "05"
or "005" would become "5"). Initially I thought I could
remove "0" with the Replace function .... however, that
would not work in all cases - example: "10" is valid,
where "01" is not.


Function CheckData(this)

' Something I am doing to all data fields
this.value = lcase(trim((this.value)))

' Remove leading zeros from IP octets
If Instr(lcase(this.name), "txtipoct") Then
If left(this.value,1) = "0" Then
' do something here
End If

End If

End Function

The relevant fields calling the function appear like this:

<INPUT TYPE="text" name="txtIPOct1" size="3" maxlength="3"
onblur=CheckData(me)><b>.</b>
<INPUT TYPE="text" name="txtIPOct2" size="3" maxlength="3"
onblur=CheckData(me)><b>.</b>
<INPUT TYPE="text" name="txtIPOct3" size="3" maxlength="3"
onblur=CheckData(me)><b>.</b>
<INPUT TYPE="text" name="txtIPOct4" size="3" maxlength="3"
onblur=CheckData(me)>

Any help or suggestions are appreciated. Regards, Doug

Re: Removing leading characters ..... by Torgeir

Torgeir
Wed Sep 17 17:45:00 CDT 2003

doug wrote:

> I have an Intranet page where users enter IP addresses. I
> have one field for each of the four octects which comprise
> an IP address. My problem is that I am getting many
> invalid entries like 165.131.01.09 instead of
> 165.131.1.9 ... basically I am looking for an event
> handler to strip any leading "0" from entries (e.g. "05"
> or "005" would become "5"). Initially I thought I could
> remove "0" with the Replace function .... however, that
> would not work in all cases - example: "10" is valid,
> where "01" is not.

Hi

txtIPOct1 = "01"
txtIPOct1 = CStr(CInt(txtIPOct1))

MsgBox txtIPOct1


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter