-
February 23rd, 2010, 04:01 PM
#1
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-.@abc.com 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
-
February 23rd, 2010, 04:34 PM
#2
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.
-
February 23rd, 2010, 07:12 PM
#3
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.
-
February 23rd, 2010, 10:11 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|