-2

The professor has asked us to do this:

Your program will receive an email address in args[0]. You must determine if it could be a real email address. This means:

There must be an '@' character in it.
There must be at least one character before the '@' character.
After the '@' character, there must be a '.' character.
There must be at least one character between the '@' character and the '.' character.
There must be at least one character following the '.' character.

I have no idea where to even start. I set up the string value of args[0]but I don't know what to do. We learned about multiple if else statements and boolean stuff in class I think he wants us to use those. Like for example how would I go about saying "The email must contain @" like how do I code for that?

Community
  • 1
  • 1

1 Answers1

-1

As others have said, the "real" answer is to use Regular Expressions, but if you haven't covered them in class yet, I doubt the professor expects you to use them. There are several functions in Javascript (which I assume you're using, and not Java) that help with parsing strings:

  1. indexOf() will tell you if one string is contained in another string. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf

  2. split() will help you figure out what's on either side of the @ symbol. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

  3. length will tell you how many characters are in a string. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length

That should give you a solid start.

fredrover
  • 2,997
  • 2
  • 17
  • 24
  • Well, looks like maybe you *are* using Java. Java has those functions, too, but you'll have to look up how exactly to use them. – fredrover Feb 05 '16 at 02:54