Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Re: validating ascii characters for a text field


Message #1 by "Jon Petter Austnes" <jon.petter@a...> on Thu, 26 Sep 2002 22:49:23
Hi Sridarti,

I have the same problem... ;D Did you find out of it? Can you or anybody 
else please help me...?


> Hi all, 

> does anyone knows how to validate ascii characters for a textfield 
input? 
i>  have currently one doen in visual basic. and is supposed to convert 
them 
t> o a javascript validation.. is not sure how its done in javascript.

> anyone able to help? below is how its done in visual basic.
-> ------------------------------------------------------------------------
-
P> ublic Function Validate_ContainerNo(ByVal vContainerNo As String, 
O> ptional ByRef vRetMsg As String = "") As Boolean

> '// ISO Container# Format: Owner Code (4) - Serial# (6) and 1 Check Digit
D> im varArray(10)
D> im intX As Integer
D> im intValue As Integer
D> im lngProduct As Long, intCheckDigit As Integer

> On Error Resume Next
 >  '// initialise
 >  Validate_ContainerNo = False
 >  vContainerNo = "" & UCase(Trim(vContainerNo))
 >  
 >  If Len(vContainerNo) <> 11 Then
 >    vRetMsg = "Insufficient digits to validate."
 >    Exit Function
 >  End If
 >  
 >  For intX = 1 To 11
 >    varArray(intX - 1) = Mid(vContainerNo, intX, 1)
 >  Next intX
 >  
 >  '// check and convert the Owner Code
 >  For intX = 0 To 3
 >    intValue = Asc(varArray(intX))
 >    If intValue >= 65 And intValue <= 90 Then
 >      If intValue = 65 Then
 >        varArray(intX) = (intValue - 55)
 >        GoTo CHKPT_ASSIGNED
 >      End If
 >      If intValue >= 66 And intValue <= 75 Then
 >        varArray(intX) = intValue - 54
 >        GoTo CHKPT_ASSIGNED
 >      End If
 >      If intValue >= 76 And intValue <= 85 Then
 >        varArray(intX) = intValue - 53
 >        GoTo CHKPT_ASSIGNED
 >      Else
 >        varArray(intX) = intValue - 52
 >        GoTo CHKPT_ASSIGNED
 >      End If
 >      
C> HKPT_ASSIGNED:
 >      varArray(intX) = CInt(varArray(intX)) * (2 ^ intX)
 >    Else
 >      vRetMsg = "Invalid Owner Code."
 >      Exit Function
 >    End If
 >  Next intX
E> nd function

> thank you. will appreciate it. 

> 
s> ri

  Return to Index