Reputation: 4532
I am using the following reg ex to validate whether the given value's length is more than zero
Regex : .*\S.*;
value : test
and this the method i use to test :
public boolean isValidInput(String pattern, String value) {
boolean isValid = false;
Pattern walletInputPattern = Pattern.compile(pattern);
Matcher walletMatcher = walletInputPattern.matcher(value);
if (walletMatcher.matches()) {
isValid = true;
}
return isValid;
}
but it returns false
desired output
Thanks
Upvotes: 0
Views: 80
Reputation: 4532
I have used Regex because I don't only check for not empty or length is greater than zero with string I have so many other which uses the same method I provided.
the answer for above question is : ^(?=\\s*\\S).*$
Upvotes: 0
Reputation: 26094
Why not this simple approach?
public boolean isValidInput(String pattern, String value) {
return value != null && value.trim().length() > 0;
}
Upvotes: 1