Click here to Skip to main content
15,908,901 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I am making a game called LINGO but I've run into a few problems. In our task we are only allowed to use the letters <A-Z>, anyone knows a good solution or code for that?



Best Regards Carl
Posted
Comments
Pandya Anil 23-Nov-11 5:53am    
you want user inputs to be restricted to A to Z only ?, kindly clarify
smacke bracke 23-Nov-11 6:31am    
Yeah, sorry about that, in my text box I only want it to register the letters <a-z> any other letters like ÅÄÖ and special characters should not be registered and nothing should happened if I write them into the text box. Was that better explained?

Carl
Sergey Alexandrovich Kryukov 23-Nov-11 12:09pm    
What text box?! System.?.?...?.TextBox. Do you know there are more than one?
Tag you UI library: WPF, Forms, APS.MET, Silverlight, what?!
--SA
Sergey Alexandrovich Kryukov 23-Nov-11 12:10pm    
What is "registered"? "special characters"?
--SA

1 solution

The most simple method I can think of is to create a string that contains the legal characters, and then check the input against that string

C#
string validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

if (validChars.Contains(input[input.Length -1])
{
    // it's valid
}
 
Share this answer
 
Comments
smacke bracke 23-Nov-11 6:31am    
I am going to try your solution now, thank you John!

Carl

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