In my web application, I have text box where the user should enter characters ranging from 5 to 200 characters.
The problem is – when the user eneter 5 whitespaces continuously and saves the entry, it is getting saved successfully.
I should BLOCK the user to enter the ‘whitespaces’ continously (or white spaces alone).
But I can allow single whitespace (like ‘customer table’, customer table’).
But I can allow the user to enter white spaces with character. Also I dont want the name starting with space.
Can anyone please help me in getting the REGEX for the above condition?
^\S+(\s\S+)*$This regexp should do what you want. It accepts non-empty strings starting with and ending with non-whitespace characters, and only with a single whitespace between words.
You should check for total string length separately.
Note that you need to escape the \ in Java.