forcing alphanumeric entry

webguy

Member
Do any of you have a routine that checks a string is alphanumeric. Not that it contains letters or numbers, but that it contains a combination of letters and numbers.


I tried this
if length(trim(ip-passwd, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")) ne 0 then
assign op-error = op-error + "Passwords must contain a combination of letters and numbers.".

But it doesnt work well.

It should work something like this:
If I enter "123456" it wont pass

If I enter "abcdef" it wont pass.

If I enter something like "abcdef2" it would pass.
 

medu

Member
you might want to look into regex for that kind of thing... something along the line

Code:
function checkAlpha (txt) {
  return !/[^a-z0-9]/i.test(txt);
}
 

FrancoisL

Member
Code:
FUNCTION VerifAlphaNum RETURNS LOGICAL
   (INPUT pcString AS CHAR):

DEF VAR lAlpha AS LOGICAL INIT FALSE.
DEF VAR lNum AS LOGICAL INIT FALSE.
DEF VAR iPos AS INT.
DEF VAR iAsc AS INT.

DO iPos = 1 TO LENGTH(pcString):
    iAsc = ASC(SUBSTRING(pcString, iPos, 1)).
    IF (iAsc >= 65 AND iAsc <= 90) OR (iAsc >= 97 AND iAsc <= 122) THEN
        lAlpha = TRUE.

    IF (iAsc >= 48 AND iAsc <= 57) THEN
        lNum = TRUE.

END.

RETURN (lAlpha AND lNum).
END FUNCTION.
 
Top