How to solve the Codewars's Regex validate PIN code

Today I try to solve the algorithm problem of codewars.

Description

ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits.

If the function is passed a valid PIN string, return true, else return false.

Example

  • Solution.validatePin(“1234”) -> true

  • Solution.validatePin(“12345”) -> false

  • Solution.validatePin(“a234”) -> false

Code

  • charAt() : returns the character at the String’s specified index.
public class Solution {
  public static boolean validatePin(String pin) {
    # Codewars COC 정책으로 인하여 코드 제거
    return false;
  }
}
Written on December 17, 2018