SELECT count(*)
FROM dual
WHERE regexp_like ('ABC-123', '^[a-zA-Z0-9]*$');
I would like to use Oracle's regexp_like to only allow the following:
If you plan to match a hyphen, the ones inbetween a-z
, A-Z
and 0-9
are not literal hyphens, they are functional characters defining a range.
You need to add a hyphen to the end of the [...]
:
^[a-zA-Z0-9-]*$
^
To avoid empty matches, use
^[a-zA-Z0-9-]+$
^