I want users to be able to enter a date format string so they can specify how they want a date value to be displayed/entered.
How can I validate this date format st
you could create a function:
e.g:
FUNCTION is_valid_date_format (
p_format IN VARCHAR2 )
RETURN BOOLEAN IS
l_date VARCHAR2(100) := NULL;
BEGIN
l_date := TO_char( sysdate, p_format );
RETURN TRUE;
EXCEPTION
WHEN OTHERS THEN
RETURN FALSE;
END is_valid_date_format;
and use it like this
IF is_valid_date_format('dd/mm/yyyy') THEN
at the moment it will allow time formats too, however it would be simple to extend it to disallow a format that contains undesired formats e.g: hh hh24 mi ss
by adding: (you will probably want to uppercase your format string first)
IF INSTR(p_format,'HH')>0 OR INSTR(p_format,'HH24')>0
OR INSTR(p_format,'MI')>0 OR INSTR(p_format,'SS')>0 THEN
RETURN FALSE
END IF;