Sys_IsValidComputerName

Sys_IsValidComputerName(ComputerName)

Uses regular expression to test if the specified string is valid as a computername.
To pass the test, it must be no longer that 15 characters and must only contain the following characters "a-z" (upper or lowercase), "0-9", "-" and "_".

Arguments

ARGUMENT

DESCRIPTION

TYPE

ComputerName

the computer name to test

String

Return Type

Boolean, TRUE if computername is valid, otherwise function returns FALSE.

Remarks

Example

The following example test a computer name specified by the user, and loops until the supplied computer name is valid.

Private Function IncludeScript(sScriptFile)
 '...
End Function

'Begin
  bStatus=True
  If bStatus Then bStatus=IncludeScript("customlib.cis")
  If bStatus Then bStatus=IncludeLibrary("Capalib.cin")
  If bStatus Then bStatus=IncludeLibrary("Osdlib.cin")
  If bStatus Then bStatus=Job_Start("WS","Script Name","1.0","ScriptName.log","INSTALL")
  If bStatus Then bStatus=OSD_Initialize()

  Do 
    bValidName=False
    'Display inputbox to user
    sRequestedComputername=InputBox("Enter computer name for this computer." & vbCrLf & vbCrLf &_
        "Name can be between 1 and 15 characters long," & vbCrLf &_
        "and can contain the following characters:" & vbCrLf & vbCrLf &_
        "'a-z'  'A-Z'  '0-9'  '-'  '_'","CapaInstaller OSD",sRequestedComputername)
    
    'validate length
    If Len(sRequestedComputername) >15 Then
        bStatus=Dialog_ShowWarning("The name specified is longer that 15 characters!")
    Else
        'test for valid charaters.
        bValidName=Sys_IsValidComputerName(sRequestedComputername)
        If Not bValidName Then bStatus=Dialog_ShowWarning("The name specified contains illegal characters!")
    End If
        
  Loop Until bValidName
  

  Job_End(bStatus)
'End main

See Also

IncludeScript function, Dialog_ShowWarning