Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to check Not Null values and empty strings

Tags:

regex

What would be the regular expression to check a string value is "Not null and not empty" in java? i tried like this "/^$|\s+/", but seems not working.

like image 866
Ratha Avatar asked Dec 25 '22 12:12

Ratha


1 Answers

Considering this: your string can not contain "null" as string:

String.valueOf(input).matches("^null|$");

Otherwise check input != null and remove null| from the regex.

like image 69
Sabuj Hassan Avatar answered Feb 23 '23 08:02

Sabuj Hassan