Skip to main content
GameDev.net gamedev.net
🔒 Locked

valid names

Started by popcorn Aug 21, 2007 at 10:06 PM 0 replies 1.4k views
Original Post
popcorn
popcorn
The first part of this project requires the need for a name but with some restrictions so I have a few questions: 1. How do you detect that only letters, apostrophes and hyphens have been entered? 2. If you type in the following names how should the program deal with it: Jachom'-Death----Bringer Jachom 'Death----'Bringer
How about them apples?
JWalsh
JWalsh
Popcorn,

System.Char (which is the struct that backs character data) has methods for determining such things.

For example: "IsControl" "IsDigit" "IsLetter" "IsLetterOrDigit", etc...

Check out MSDN for more information.

As for the second part of your question, it's up to you to assign priority to each of the symbols, and to determine which should and should not appear.

One simple solution is any time you have a space, hyphen, or apostrophe, followed by any combination of the three, you keep the first, and discard all the rest.

That would turn your two examples into:
Jachom'Death-Bringer
Jachom Death-Bringer

You could also assign priorities, such as spaces are always kept when combined with other symbols, and hyphens over power apostrophes, etc..

Again, it's entirely up to you.

Cheers!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.