# Sys_IsValidComputerName

> Uses regular expression to test if the specified string is valid as a computername.

Source: https://docs.capaone.com/capainstaller/vb-scripting-library/osd-scripting-library/system-functions-osd/sys-isvalidcomputername/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

[VB Scripting Library](/capainstaller/vb-scripting-library/) > [OSD Scripting Library](/capainstaller/vb-scripting-library/osd-scripting-library/) > [System functions (OSD)](/capainstaller/vb-scripting-library/osd-scripting-library/system-functions-osd/)

### 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.

**VBScript**

```vb
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

[Scripting Guidelines](/capainstaller/vb-scripting-library/scripting-guidelines/), [Dialog_ShowWarning](/capainstaller/vb-scripting-library/osd-scripting-library/dialog-functions-osd/dialog-showwarning/) [Constants](/capainstaller/vb-scripting-library/addendum/constants/) [Package Property](/capainstaller/vb-scripting-library/addendum/package-property/) [Variables](/capainstaller/vb-scripting-library/addendum/variables/)
