webtier@glassfish.java.net

Re: Validating against repeated words using JSF

From: <webtier_at_javadesktop.org>
Date: Thu, 20 May 2010 21:06:37 PDT

Hi,
the regular expression you need is this: (?!.*\b(\w+)\b\s+\1\b).*

try this out:

        <h:form>
            <h:inputText required="true" id="str" validatorMessage="error: string contains adjacent repeated words">
                <f:validateRegex pattern="(?!.*\b(\w+)\b\s+\1\b).*" />
            </h:inputText>
            <h:message for="str"/>
            <h:commandButton value="check" />
        </h:form>

note: In the pattern attribute for validateRegex , i didn't escape the backslashes as you would do in the normal java code. If you escape, you wont get the desired results.See this for the backslash issue: http://forums.sun.com/thread.jspa?threadID=5439029&tstart=-1
[Message sent by forum member 'nash_era']

http://forums.java.net/jive/thread.jspa?messageID=470828