title: Valid filename check. What is the best way?
body: <p>See subject of positing for question.</p>
  
  <p>1) I recall seeing a really cool option in VB.NET using LINQ to match using "LIKE%'</p>
  
  <p>2) I know regular expressions will work and I suspect that will result in the shortest code and probably won't be too hard to read for such a simple test.</p>
  
  <p>Here's what I did. Warning: You're gonna hate it.</p>
  
  <pre><code>Private Shared Function FileNameIsOk(ByVal fileName As String) As Boolean
  
      For Position As Integer = 0 To fileName.Length - 1
  
          Dim Character As String = fileName.Substring(Position, 1).ToUpper
          Dim AsciiCharacter As Integer = Asc(Character)
  
          Select Case True
  
              Case Character = "_" 'allow _
              Case Character = "." 'allow .
              Case AsciiCharacter &gt;= Asc("A") And AsciiCharacter &lt;= Asc("A") 'Allow alphas
              Case AsciiCharacter &gt;= Asc("0") AndAlso AsciiCharacter &lt;= Asc("9") 'allow digits
  
              Case Else 'otherwise, invalid character
                  Return False
  
          End Select
  
      Next
  
      Return True
  
  End Function
  </code></pre>