cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
tech_is
Level 5

Validating Serial number

Hi,

I wanted to validate the serial number of the product (which is preferably of 3 characters) by checking that if the serial number entered is only NUMERIC and no alphabets.

Please help with any regex:confused: or internal function:confused: which shall validate the serial number.

Thanks in advance. 🙂
Labels (1)
0 Kudos
(1) Reply
MGarrett
Level 6

There are several ways to do it.
You could use the builtin function StrToNum() and test if it was successful. Be careful here, as it will discard any non-numeric characters after the first one is found. See the help for StrToNum for more information.

Since you mention that you are using only 3 characters for the serial number, you can then test if the resulting value is between 0 and 999.

if( StrToNum(nvSerial, szSerial) != 0 ) then
//fail
else
if( nvSerial >= 0 && nvSerial <= 999 ) then
// successfull
else
//fail
endif;
endif;



For more fine-grained control, you could write your own function. Below is a similar one to what we use. Note that it assumes entry is in ASCII characters.

[CODE]function BOOL IsNumericString(sBuffer)
BOOL bNumeric; //Flag indicates if string content is purely ASCII numeric
NUMBER nCount; // counter for characters
begin
bNumeric = TRUE;
for( nCount = 0 to (StrLengthChars(sBuffer) - 1) )
if( sBuffer[nCount] < 16 || sBuffer[nCount] > 25 ) then
bNumeric= FALSE;
endif;
endfor;
return bNumeric;
end;[/CODE]
0 Kudos