Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.temp.shared.validators;

import com.temp.shared.ValueValidator;
import com.temp.shared.externalization.E13nData;
import com.temp.shared.utils.StringUtils;

/**
 * Phone Number Validator, that requires at a minimum that a phone number not be
 * empty!
 *
 * This lame validation was copied from the Client utils.Util.java class.
 *
 * @author georgs
 */
public class PhoneValidator implements ValueValidator<String> {

    public enum ErrorTemplateIdCode {
        PhoneEmpty, //
        PhoneNoCtrlCharsAllowed
    }

    public static final PhoneValidator INSTANCE = new PhoneValidator();

    protected PhoneValidator() {
    }

    public boolean isValid(String phone) {
        return (null == checkValue(phone));
    }

    @Override
    public E13nData checkValue(String phone) {
        phone = StringUtils.noEmpty(phone);
        if (phone == null) {
            return new E13nData(ErrorTemplateIdCode.PhoneEmpty);
        }
        int at = StringUtils.indexOfControlCharacter(phone);
        if (at != -1) {
            return new E13nData(ErrorTemplateIdCode.PhoneNoCtrlCharsAllowed);
        }
        return null;
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/shared/validators/PhoneValidator.java

Diff revisions: vs.
Revision Author Commited Message
626 GeorgeS picture GeorgeS Wed 11 Apr, 2012 19:39:41 +0000