H
Heyoka955
Gast
1
Write a function that accepts a string, and returns true if it is in the form of a phone number.
Assume that any integer from 0-9 in any of the spots will produce a valid phone number.
Only worry about the following format:
(123) 456-7890 (don't forget the space after the close parentheses)
Examples:
validPhoneNumber("(123) 456-7890") => returns true
validPhoneNumber("(1111)555 2345") => returns false
validPhoneNumber("(098) 123 4567") => returns false
Der test sagt mir
formCharTests
badCharTests
Be careful with non-digit characters inside phone number expected:<false> but was:<true>
Stack Trace
basicTests
Follow the formatting instructions carefully expected:<false> but was:<true>
Stack Trace
charTests
Be careful with characters surrounding the phone number expected:<false> but was:<true>
Write a function that accepts a string, and returns true if it is in the form of a phone number.
Assume that any integer from 0-9 in any of the spots will produce a valid phone number.
Only worry about the following format:
(123) 456-7890 (don't forget the space after the close parentheses)
Examples:
validPhoneNumber("(123) 456-7890") => returns true
validPhoneNumber("(1111)555 2345") => returns false
validPhoneNumber("(098) 123 4567") => returns false
Der test sagt mir
formCharTests
badCharTests
Be careful with non-digit characters inside phone number expected:<false> but was:<true>
Stack Trace
basicTests
Follow the formatting instructions carefully expected:<false> but was:<true>
Stack Trace
charTests
Be careful with characters surrounding the phone number expected:<false> but was:<true>
Java:
public class Kata {
public static boolean validPhoneNumber(String phoneNumber) {
if(phoneNumber.charAt(0) == '('){
if(phoneNumber.charAt(1) == '1' ){
if(phoneNumber.charAt(2) == '2' ){
if(phoneNumber.charAt(3) == '3' ){
if(phoneNumber.charAt(4) == ')'){
return true;
}
}
}
}
}
return false;
}
}