This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Re: Validating Serial number
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Aug 26, 2008
07:27 AM
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. 🙂
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. 🙂
(1) Reply
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Aug 26, 2008
11:34 AM
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.
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]
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]
![](/skins/images/8CE4FAD0DE6F3A6F9D0567434D2D2DAE/responsive_peak/images/icon_anonymous_message.png)