Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to return false on each of this numbers, so when i type down hello 1 or hello 2 or hello 1234567890 etc. it return false

What I have tried:

C#
public bool Aliasnaamcontrole(string Alias)
        {
  
            if (Alias.Contains("1234567890"))
            {
                return false;
            }
Posted
Updated 4-Jan-18 10:20am
v2
Comments
Maciej Los 4-Jan-18 16:21pm    
Sorry... i do not understand you...

1 solution

You could use a regular expression: add using System.Text.RegularExpressions; to the top of your code file, and in your method:
C#
if (Regex.IsMatch(Alias, "[0-9]"))
{
    return false;
}

[0-9] is a regular expression[^] that means "a number from 0 to 9". Regex.IsMatch checks if 'Alias' matches that and if it does, your method returns false. So, it will return false for "hello 1", "hello 2", "hello 12345" and everything else that contains a number.
 
Share this answer
 
Comments
Member 13554627 4-Jan-18 16:24pm    
sounds good, the only things is that i have to use the contain method and if i put in this it doesnt seems to work :/

if (Alias.Contains("[0-9]"))
{
return false;
}
Thomas Daniels 4-Jan-18 16:26pm    
Yes, that's wrong usage: you must use Regex.IsMatch or this will not work.

If you really have to use Contains, I don't see another option than something like Alias.Contains("0") || Alias.Contains("1") || ...
Member 13554627 4-Jan-18 16:28pm    
ah allright, thats too bad. thanks anyway i appreciate your help!
Thomas Daniels 4-Jan-18 16:28pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900