Rebecca
Rebecca

Reputation: 21

APEX validate alphabetic only allowed

In APEX 5.1 looking for validation script help to only allow alphabetic characters and a space or hyphen for a person's name. (i.e. no numbers or special characters other than a possible dash allowed).

I have a working validation for another field which allows alphanumeric but not special characters! Validation type is "Item does NOT contain any of the characters in Value". In the value field the following is placed... !@#$%^&*()-_+=[]{};:'",<.>/?\|

Upvotes: 1

Views: 2646

Answers (1)

Littlefoot
Littlefoot

Reputation: 143063

I'd suggest you to use validation whose type is a function that returns Boolean and looks like this:

return regexp_like(:P1_ITEM_NAME, '^[A-Za-z -]+$');

What does it do?

  • ^ is anchor to the beginning of the string
  • A-Z accepts capital letters
  • a-z accepts lowercase letters
  • space is ... well, a space
  • - is ... well, a hyphen
  • + - repeat those characters many times
  • $ is anchor to the end of the string

For example:

SQL> with test (item) as
  2    (select 'aBCd'        from dual union  -- ok
  3     select 'little foot' from dual union  -- ok
  4     select 'reb-ecca'    from dual union  -- ok
  5     select 'lit123foot'  from dual union  -- wrong
  6     select 'abc$3'       from dual union  -- wrong
  7     select 'xy.)z'       from dual union  -- wrong
  8     select '123-234'     from dual        -- wrong
  9    )
 10  select item
 11  from test
 12  where regexp_like(item, '^[A-Za-z -]+$');

ITEM
-----------
aBCd
little foot
reb-ecca

SQL>

Upvotes: 2

Related Questions