вторник, 18 марта 2014 г.

Валидация поля номера счета


    public void onEdateToValidation(FacesContext facesContext, UIComponent uIComponent, Object object) {
            if (object != null)
            {
              String name = object.toString();
              //      String expression = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
              String expression = "[0-9]{1,20}";
              CharSequence inputStr = name;
              Pattern pattern = Pattern.compile(expression);
              Matcher matcher = pattern.matcher(inputStr);
              String msg = "Кореспондентский счет может содержать только цифры. Длинна поля - в точности 20 символов.";
              if ((matcher.matches() && inputStr.length() == 20) || name.isEmpty())
              {

              }
              else
              {
                throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
              }
            }
    }