Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Validating only digits

Former Member
0 Kudos

Hi All

I want to validate a field with digits only ( 0 to 9) . If it contains other than 0 to 9 digits like special characters then it should fail.

for e.g. : 384746 should be true

384-746 should be false.

If I use CA operand then it throws true even for 384-746 value

Can anybody let us know how to achieve it ? is there any FM available .

I got it with some extra logic to find it out whether it is a numeric or not BUT I need a direct method , one step validation

Responses are highly appreciated .

Satya

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Try:


IF f1 CO '0123456789'.
* Good
ELSE.
* No good.
ENDIF.

7 REPLIES 7

Former Member
0 Kudos

Try:


IF f1 CO '0123456789'.
* Good
ELSE.
* No good.
ENDIF.

0 Kudos

Hi

Thanks for ur response

If f1 = 65883 then it is fine

if f1 = 659-675 then it should fail

The above condition should execute .there are some cases where special characters are possible.

0 Kudos

Hi,

The code provided by Rob will work in the cases you provided. What is the issue then.

Regards,

Atish

0 Kudos

Would you mind letting us know what the "special cases" are?

Rob

naimesh_patel
Active Contributor
0 Kudos

Try like this:

[code]REPORT ZTEST_NP.

parameters: l_text(10) type c.

data: l_num(12) type c value '-+=@#$%^&*()'.

if l_text ca l_num.

write: 'false'.

else.

write: 'true'.

endif.[/code]

Regards,

Naimesh Patel

Former Member
0 Kudos

Hi Satya,

try like this

if field CO '0123456789'.

then process...

else.

exit.

endif.

Reward points if it helps,

Satish

Former Member
0 Kudos

Thanks