Finding Consecutive Chars in a String
I'm trying to write an email validation program, and I'm having a lot of trouble finding a way to check a string for invalid consecutive chars. Specifically, emails cannot have a repeated ".", "-", or combination of these two chars, so [email protected] is invalid.
Does anyone have any ideas on how I could approach this? In particular, the "-." and ".-" possibilities are messing me up.
Any help would be appreciated!
Thanks,
--valhalla8
Re: Finding Consecutive Chars in a String
Read the string one character at a time. Compare the current character to the next character until you find an invalid match or you run out of characters.
Re: Finding Consecutive Chars in a String
Personally, I'd probably just strstr() it (or string::find() it) for each invalid possibility at a time. Slightly less efficient, but easier.
Re: Finding Consecutive Chars in a String
Thanks a lot guys. I tried to do the first way but I'm retarded so I couldn't figure it out without making a huge nested for/if loop, so I'll probably have to stick with the second way and hope my professor finds it acceptable.