Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: isnumber ischaracter ip address
I would like to know if there is an easy way to get an entry field where the user would input information that would be automatically validated as the user is entering information ie. the user would not be able to enter letters where numbers are required and vice-versa !!!
Please let me know if anyone would have a solution for this problem.
Here is some code I threw together which *attempts* to validate an IP Address...
#definefunction MainWnd(dlghandle,dlgmessage,dlgID,reserved4,reserved5) ;Define a few handy constants here MSG_Initialization=0 MSG_EDITBOX=5 DCTL_EditBox = 3 switch dlgmessage case MSG_Initialization ; The Dialog Initialization call dialogprocoptions(dlghandle,MSG_EDITBOX,@true) break case MSG_EDITBOX ebval=dialogcontrolget(dlghandle,dlgID,DCTL_EditBox) ;Check string either integer or (.) check = CheckIPAddress(ebval) if check == @False message("NOTE","Not a valid ip address") endif break endswitch return (-1) ; do default processing #endfunction #DefineFunction CheckIPAddress(szAddr) ;Check string is no longer than 15 characters if StrLen(szAddr)>15 ;Message("NOTE","Not a valid ip address") Return @False endif ;Check there are 4 octets in the string OctetCount = ItemCount(szAddr, '.') if OctetCount <> 4 ;Message('Error', 'Malformed IP address') Return @False endif for i = 1 to 4 Octet = ItemExtract(i, szAddr, '.') if Octet < 0 || Octet > 255 || !IsNumber(Octet) ;Message('Not Valid IP Address', StrCat('Octet #', i, ' is not numeric between 0 and 255') Return @False endIf next Return @true #EndFunction DlgFormat=`WWWDLGED,6.1` DlgCaption=`Validate Text` DlgX=002 DlgY=050 DlgWidth=225 DlgHeight=121 DlgNumControls=004 DlgProcedure=`MainWnd` DlgFont=`DEFAULT` DlgTextColor=`DEFAULT` DlgBackground=`DEFAULT,DEFAULT` Dlg001=`057,082,033,011,PUSHBUTTON,DEFAULT,"OK",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT` Dlg002=`111,082,033,011,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` Dlg003=`042,047,117,011,EDITBOX,IPaddr,"",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` Dlg004=`041,033,127,011,STATICTEXT,DEFAULT,"Please enter an IP Address in the form ###.###.###",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("Dlg") ;Check string either integer or (.) check = CheckIPAddress(IPaddr) if check == @False message("NOTE","Not a valid ip address") endifYou would have to modify the code to fit your exact needs....
Article ID: W15125
File Created: 2004:03:18:10:46:02
Last Updated: 2004:03:18:10:46:02