Page 1 of 1

Check whether string consists of alphanumeric characters

Posted: Tue Oct 03, 2006 1:50 pm
by DeepakCorning
I was searching the Help Guide and found out that we have the follwing function in Parallel Edition --

AlNum
Return whether the given string consists of alphanumeric characters

DO we have a equivalent in Server Edition??

Posted: Tue Oct 03, 2006 2:02 pm
by kris007
I couldn't find a direct one but you could play around with DIGITS and LETTERS built-in transform functions and alpha function. Or are you already aware of them?

Posted: Tue Oct 03, 2006 2:11 pm
by DeepakCorning
Yep , Aware of them...Was searching for a direct one. But if not there then let me try to use these one somwhow. Thanks !!

Posted: Tue Oct 03, 2006 4:45 pm
by ray.wurlod
There isn't a direct one. You could create a direct one.

Code: Select all

FUNCTION AlNum(TheString)
* Returns 1 (true) if all characters are alphanumeric, 0 (false) otherwise.
   Ans = @TRUE
   CharCount = Len(TheString)
   For ch = 1 To CharCount
      Character = TheString[ch,1]
      If Character Matches "1A" : @VM : "1N"
      Else
         Ans = @FALSE
         Exit  ; * as soon as a non-alphanumeric character found exit loop
      End
   Next ch
RETURN(Ans)

Posted: Tue Oct 03, 2006 7:17 pm
by avi21st
This is another way in which you can do it...........

Code: Select all

Input = TRIM(aNUMBERFIELD)
*********************************************************
*The function gets the non-numeric fields from the Input*
*********************************************************
Convert= Iconv(Input,"MD")

ConvStatus= Status()
*************************************************************************
* Output:  1 if there is error or warning in conversion                 *
*          0 if the conversion is successful                            *
*************************************************************************
Begin Case
Case (ConvStatus=1 or ConvStatus=2 or ConvStatus=3)
Output=1
Case ConvStatus=0
Output=0
End Case
Ans= Output

Ans= Output

Posted: Tue Oct 03, 2006 8:38 pm
by ray.wurlod
ALPHAnumeric was specified in the subject.

Posted: Tue Oct 03, 2006 11:29 pm
by avi21st
ray.wurlod wrote:ALPHAnumeric was specified in the subject.

Sorry I pasted the wrong one............

Code: Select all

Input = VarCharField

**********************************************************

*The function gets the non-numeric fields from the Input*

**********************************************************

Charac= Iconv(Input,"MC/N")

***************************************************************

*The function counts the non-numeric fields in the result set*

***************************************************************


NumofCharac= Len(Charac)

Begin Case

Case (NumofCharac >0)

Output=1

Case (NumofCharac=0)

Output=0

End Case

Ans= Output

Arg1 = Input field(Varchar: Datatype)

Called by:
Transformer

Parameters:
Arg1 = Input field


Checks for non-numeric character in numeric field.

Return Values: 0 = If the Input Field does NOT have non-numeric character
1 = If the Input Field has non-numeric character

Posted: Tue Oct 03, 2006 11:50 pm
by ray.wurlod
You've still missed the point. The OP required detection of non-alphanumerics, not non-numerics.