id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

welcomeback_regex_phoneOrName


Given a String, return "phone" if it is a phone number, "name" if it is a name, and "neither" if it is neither. Phone numbers must be 3 digits, a dash, 3 digits, a dash, and then 4 digits. A name must be a capital letter followed by 1 or more lowercase letters. The names will only be last names with no spaces. Note: You cannot import java.util.regex, instead use the String class method "matches" as shown below.

String phonePattern = "YOUR CODE GOES HERE";
if(input.matches(phonePattern)) {
  return "phone";
}

welcomeback_regex_phoneOrName("123-456-7890") → "phone"
welcomeback_regex_phoneOrName("123-456-78900") → "neither"
welcomeback_regex_phoneOrName("Monroe") → "name"

...Save, Compile, Run (ctrl-enter)

public String welcomeback_regex_phoneOrName(String input) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy