Invalid IP Address

This example uses a C1MaskedInput control with the custom mask: <<0...255>>\.<<0...255>>\.<<0...255>>\.<<0...255>>. For details on setting the control's Mask property, see Creating an IP Address Mask.

To display an alert box for an incomplete IP address, complete the following steps:

1.   Select the Input for ASP.NET AJAX control, in this case, C1MaskedInput. Note that for this example the ID property for the control was changed to _IPAddress.

2.   From the Visual Studio Properties window, locate the client-side event, OnClientBlur.

3.   Click the OnClientBlur drop-down arrow and select Add New Client Side Handler.

 

 

Note that the drop-down list also lists functions currently defined on your Web form.

4.   Your screen will automatically change to Code view and highlight the new function. Enter the following code inside the OnClientBlur function (replacing the code comment which is automatically inserted):

 

var aTextEntered = aC1Edit.get_TextWithLiterals();

//The mask is:

//<<0...255>>\.<<0...255>>\.<<0...255>>\.<<0...255>>

var arr = aTextEntered.split(".");

arr[0] = parseFloat(arr[0]);

arr[1] = parseFloat(arr[1]);

arr[2] = parseFloat(arr[2]);

arr[3] = parseFloat(arr[3]);

if(arr[0] < 1 || arr[1] < 1 || arr[2] < 1)

alert("You must enter a valid IP address!");   

This topic illustrates the following:

Run the project. Begin typing the IP address and leave the input control before entering the entire address, and you will receive an alert box:

 

 


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.