001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: AlphaValidator.java,v 1.3 2008/06/25 05:41:47 qcheng Exp $
026 *
027 */
028
029/**
030 * Portions Copyrighted [2011] [ForgeRock AS]
031 */
032package com.iplanet.ums.validation;
033
034/**
035 * This class implements IValidator interface. Use the validate method of this
036 * class to validate the string for alphabetic string. Pass the string to be
037 * alphabeticvalidated and optional rule to validate function. The function
038 * returns true value if the string is valid alphabetic string
039 *
040 * @supported.all.api
041 */
042public class AlphaValidator implements IValidator {
043
044    /**
045     * Determines whether the specified string is a valid
046     * alphabetic string
047     * 
048     * @param value
049     *            string value to validate
050     * @param rule
051     *            not used by this method
052     * @return true if value is an alphabetic string
053     */
054    public boolean validate(String value, String rule) {
055        return validate(value);
056
057    }
058
059    /**
060     * Determines whether the specified string is a valid
061     * alphabetic string
062     * 
063     * @param value
064     *            string to test
065     * @return true if value is an alphabetic string
066     */
067    public boolean validate(String value) {
068        char aChar;
069
070        StringBuilder buf = new StringBuilder(value);
071
072        for (int aIndex = 0; aIndex < buf.length(); aIndex++) {
073            aChar = buf.charAt(aIndex);
074
075            if (!Character.isSpaceChar(aChar)) {
076                if (!Character.isLetter(aChar)) {
077                    return false;
078                }
079            }
080        }
081
082        return true;
083    }
084}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.