package ru.bildovich.start;

/**
 * Created by mac on 24.03.17.
 * Class
 */
public class ValidateInput extends ConsoleInput {

    @Override
    public String ask(String question) {
        return super.ask(question);
    }

    @Override
    public int ask(String question, int[] range) {

        boolean invalid = true;

        int value = -1;

        do {
            try {
                value = super.ask(question, range);
                invalid = false;
            } catch (MenuOutExeption moe) {
                System.out.println("Pleas select key from menu");
            } catch(NumberFormatException nfe) {
                System.out.println("Pleas enter validate data again!");
            }
        } while (invalid);

        return value;

    }

    public String askId(String question) {
        boolean invalid = true;
        String value = "";

        do {
            value = super.ask(question);
           try {
               checkId(value);
               invalid = false;
           } catch (IdExeption ie) {
               System.out.println("Pleas enter validate ID again!");
           }
        } while (invalid);

        return value;
    }

    private boolean checkId(String id) throws IdExeption{
        try {
            Integer.valueOf(id);
            return true;
        } catch (NumberFormatException ie) {
            throw new IdExeption(id);
        }
    }
}

@@ -22,16 +22,81 @@
 start;%0A%0A
+import java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0A
 /**%0A * C
@@ -182,24 +182,64 @@
 oleInput %7B%0A%0A
+    private final String MP = %22(/d+)%22;%0A%0A
     @Overrid
@@ -1338,24 +1338,25 @@
 eption%7B%0A
+%0A
         
 try %7B%0A  
@@ -1351,46 +1351,109 @@
     
-try %7B%0A            Integer.valueOf(id);
+Pattern p = Pattern.compile(%22%5B0-9%5D+%22);%0A        Matcher m = p.matcher(id);%0A%0A        if (m.matches()) %7B
 %0A   
@@ -1488,40 +1488,12 @@
   %7D 
-catch (NumberFormatException ie)
+else
  %7B%0A 
@@ -1535,20 +1535,21 @@
 ;%0A        %7D%0A
+%0A
     %7D%0A%7D%0A

add 7_1