Hi mahesh213,
Use RegularExpressions to validate.
Check this example. Now please take its reference and correct your code.
Code
C#
public bool checkUsernamevalid(string username)
{
bool isValid = false;
var regx = new System.Text.RegularExpressions.Regex("^[a-zA-Z-']*$");
if (regx.IsMatch(username))
{
if (username.StartsWith("-"))
{
isValid = false;
}
else
{
isValid = true;
}
}
else
{
isValid = false;
}
return isValid;
}
VB.Net
Public Function checkUsernamevalid(ByVal username As String) As Boolean
Dim isValid As Boolean = False
Dim regx = New System.Text.RegularExpressions.Regex("^[a-zA-Z-']*$")
If regx.IsMatch(username) Then
If username.StartsWith("-") Then
isValid = False
Else
isValid = True
End If
Else
isValid = False
End If
Return isValid
End Function