Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 IsValidName Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
INameCreationService..::.IsValidName Method

Gets a value indicating whether the specified name is valid.

Namespace:  System.ComponentModel.Design.Serialization
Assembly:  System (in System.dll)
Visual Basic (Declaration)
Function IsValidName ( _
    name As String _
) As Boolean
Visual Basic (Usage)
Dim instance As INameCreationService
Dim name As String
Dim returnValue As Boolean

returnValue = instance.IsValidName(name)
C#
bool IsValidName(
    string name
)
Visual C++
bool IsValidName(
    String^ name
)
JScript
function IsValidName(
    name : String
) : boolean

Parameters

name
Type: System..::.String
The name to validate.

Return Value

Type: System..::.Boolean
true if the name is valid; otherwise, false.

An implementation of the INameCreationService can have rules that define the parameters for valid names. This method can be implemented to validate a name and enforce those rules.

The following code example provides an example INameCreationService..::.IsValidName method implementation. The method uses a string validation scheme that examines each character of the specified string to determine whether the specified string is a valid name. The method returns true if the string is valid, or false otherwise.

Visual Basic
' Returns whether the specified name contains 
' all valid character types.
Public Function IsValidName(ByVal name As String) As Boolean Implements INameCreationService.IsValidName
    Dim i As Integer
    For i = 0 To name.Length - 1
        Dim ch As Char = name.Chars(i)
        Dim uc As UnicodeCategory = [Char].GetUnicodeCategory(ch)
        Select Case uc
            Case UnicodeCategory.UppercaseLetter, UnicodeCategory.LowercaseLetter, UnicodeCategory.TitlecaseLetter, UnicodeCategory.DecimalDigitNumber
            Case Else
                Return False
        End Select
    Next i
    Return True
End Function
C#
// Returns whether the specified name contains 
// all valid character types.
public bool IsValidName(string name)
{            
    for(int i = 0; i < name.Length; i++)
    {
        char ch = name[i];
        UnicodeCategory uc = Char.GetUnicodeCategory(ch);
        switch (uc) 
        {
            case UnicodeCategory.UppercaseLetter:       
            case UnicodeCategory.LowercaseLetter:     
            case UnicodeCategory.TitlecaseLetter:                                                  
            case UnicodeCategory.DecimalDigitNumber:                         
                break;
            default:
                return false;                
        }
    }
    return true;        
 }
Visual C++
// Returns whether the specified name contains 
// all valid character types.
virtual bool IsValidName( String^ name )
{
   for ( int i = 0; i < name->Length; i++ )
   {
      Char ch = name[ i ];
      UnicodeCategory uc = Char::GetUnicodeCategory( ch );
      switch ( uc )
      {
         case UnicodeCategory::UppercaseLetter:
         case UnicodeCategory::LowercaseLetter:
         case UnicodeCategory::TitlecaseLetter:
         case UnicodeCategory::DecimalDigitNumber:
            break;

         default:
            return false;
      }
   }
   return true;
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker