I have a data of day and I need to check if it contain only 0. How I can check if string contain only 0? I want to do it with regular expressions.
Asked
Active
Viewed 9,949 times
3 Answers
15
/^0*$/.test(subject)
returns True
for a string that contains nothing but (any number of, including 0) zeroes. If you don't want the empty string to match, use +
instead of *
.

Tim Pietzcker
- 328,213
- 58
- 503
- 561
1
In my case I've used match()
var subject = /^0+$/;
var starting_date = '00000000'
if (starting_date.match(subject)) {
return true;
}

khashashin
- 1,058
- 14
- 40
1
I was filtering empty strings of binary and this seemed the most intuitive solution
!+"000" // true
!+"0010" // false

Jonatan
- 11
- 1