Reputation: 3990
Trying to create a regex that allows typing in the following input into a html input:
^[^1-9]{0,1}[0-9\\s-\\/]*$
With the following regex I cannot delete the 0...
^0[0-9\\s-\\/]*$"
Upvotes: 1
Views: 96
Reputation: 67988
^(?:0[0-9 \\/-]*|)$
You can use this instead.See demo.This will allow empty
as well as strings starting from 0
.
https://regex101.com/r/uF4oY4/18
Upvotes: 0
Reputation: 23870
Add a non-capturing group (?:...)
around everything between ^
and $
, and use the ?
operator on it (allow zero or one):
^(?:0[0-9\\s-\\/]*)?$
Upvotes: 3