1. Voppichler Frank
  2. PowerBuilder
  3. Friday, 7 July 2023 06:40 AM UTC

Hi all,

i have a DW regular expression for digits:

Match( GetText(), "^[0-9,]+$") 

This works well with positive digits. Now i want to check negative digits:

Match( GetText(), "^[0-9,-]+$") 

This throws an execption when i entered a "-" as first character.

Any ideas to solve the problem.

Thanks.

Frank

Voppichler Frank Accepted Answer Pending Moderation
  1. Friday, 7 July 2023 09:41 AM UTC
  2. PowerBuilder
  3. # 1

Hi René,

i use PowerBuilder 2022 (Build 1900).

Thanks.

Comment
  1. Voppichler Frank
  2. Friday, 7 July 2023 12:22 PM UTC
Hi Andreas,

thanks for your help. I've some code in the editchanged-event (of_AcceptText()). The function of_AcceptText has thrown the error. Both expression

^[\-]?[0-9]+$

^[0-9,-]+$

work fine. Sorry for the chaos :)



  1. Helpful
  1. Andreas Mykonios
  2. Friday, 7 July 2023 13:26 PM UTC
There is a difference between those expressions. ^[0-9,-]+$ will accept "-" and "-10-11-12" and "12-12" and "12-" as correct values... So depending to what you want to achieve be careful to choose the one you need.

Andreas.
  1. Helpful 1
  1. Francisco Martinez @Appeon
  2. Friday, 7 July 2023 14:27 PM UTC
If I'm imagining what you want correctly, a possible expression would be ^-?[0-9]+$

This would only allow integer numbers, positive or negative.
  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Friday, 7 July 2023 09:37 AM UTC
  2. PowerBuilder
  3. # 2

Hi Frank,

Match( GetText(), "^[0-9,-]+$") works for me in PB 2019 R3.

What PB version do you use?

 

Comment
There are no comments made yet.
Voppichler Frank Accepted Answer Pending Moderation
  1. Friday, 7 July 2023 08:20 AM UTC
  2. PowerBuilder
  3. # 3

Hi Benjamin,

thanks for your quick response. I tried the new expression my got the same error. Any other ideas?

Comment
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Friday, 7 July 2023 06:56 AM UTC
  2. PowerBuilder
  3. # 4

Hi Frank,

try escaping the "-" character with a backslash. As in 

Match( GetText(), "^[0-9,\-]+$") 
Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.