Skip to main content

Validating against repeated words using JSF

1 reply [Last post]
Joined: 2007-09-27

My requirement is to accept user input consists of series of words but not repeated words, which means no two same words next to each other.

It may not be a difficult task to detect repeated words using regular expression like this: \b (w+) \1 \b

But, can I do the above mentioned validation task using f:validateRegex JSF tag?

Message was edited by: sariga

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-05-10

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

try this out:

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: