Email address must be of form a@b.c -- in other words: - there must be at least one character before the @ - there must be at least one character before and after the . - the characters @ and . are both required
(String s)
| 645 | * - the characters @ and . are both required |
| 646 | */ |
| 647 | public static boolean isEmail(String s) { |
| 648 | if (isEmpty(s)) return defaultEmptyOK; |
| 649 | |
| 650 | // is s whitespace? |
| 651 | if (isWhitespace(s)) return false; |
| 652 | |
| 653 | // there must be >= 1 character before @, so we |
| 654 | // start looking at character position 1 |
| 655 | // (i.e. second character) |
| 656 | int i = 1; |
| 657 | int sLength = s.length(); |
| 658 | |
| 659 | // look for @ |
| 660 | while ((i < sLength) && (s.charAt(i) != '@')) i++; |
| 661 | |
| 662 | // there must be at least one character after the . |
| 663 | if ((i >= sLength - 1) || (s.charAt(i) != '@')) |
| 664 | return false; |
| 665 | else |
| 666 | return true; |
| 667 | |
| 668 | // DEJ 2001-10-13 Don't look for '.', some valid emails do not have a dot in the domain name |
| 669 | // else i += 2; |
| 670 | |
| 671 | // look for . |
| 672 | // while((i < sLength) && (s.charAt(i) != '.')) i++; |
| 673 | // there must be at least one character after the . |
| 674 | // if((i >= sLength - 1) || (s.charAt(i) != '.')) return false; |
| 675 | // else return true; |
| 676 | } |
| 677 | |
| 678 | /** isYear returns true if string s is a valid |
| 679 | * Year number. Must be 2 or 4 digits only. |
nothing calls this directly
no test coverage detected