2 * Copyright (C) 2016 - 2020 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.validator.phone.abroad;
19 import java.text.MessageFormat;
20 import javax.faces.application.FacesMessage;
21 import javax.faces.component.UIComponent;
22 import javax.faces.context.FacesContext;
23 import javax.faces.validator.FacesValidator;
24 import javax.faces.validator.ValidatorException;
25 import org.mxchange.jcoreee.validator.number.BaseNumberValidator;
28 * A validator for phone, fax and mobile numbers
30 * @author Roland Häder<roland@mxchange.org>
32 @FacesValidator ("AbroadDialValidator")
33 public class PizzaAbroadDialValidator extends BaseNumberValidator {
38 private static final long serialVersionUID = 186_897_817_692_786_900L;
41 public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
43 final String[] requiredFields = {"countryAbroadDialPrefix"}; //NOI18N
45 // Pre-validation (example: not null, not a string, empty string ...)
46 super.preValidate(context, component, value, requiredFields, true);
48 // Parse value as string first
49 final String dialNumber = String.valueOf(value);
52 if (!dialNumber.equals("+")) { //NOI18N
53 // No, then try to ...
56 final Long number = Long.parseLong(dialNumber);
58 // Not valid range? (1 - 99, very rude)
59 if (number < 1 || number > 99) {
61 throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, MessageFormat.format("Number {0} is not between 1 and 99 inclusive.", number), MessageFormat.format("The entered number {0} is not in the range of 1 and 99 inclusive. This cannot be used as abroad dial prefix. Alternatively enter international '+' sign.", number))); //NOI18N
63 } catch (final NumberFormatException ex) {
65 throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, "No number or + entered", "No number or + sign has been entered."), ex); //NOI18N