realbasic-nug
[Top] [All Lists]

Re: Filtering non-alphanumeric characters

To: realbasic-nug at lists dot realsoftware dot com
Subject: Re: Filtering non-alphanumeric characters
From: Rob Laveaux <rob dot laveaux at pluggers dot nl>
Date: Fri, 30 Dec 2005 01:07:36 +0100
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20051229062942 dot CEACDF9818A at lists dot realsoftware dot com>

On 29-dec-2005, at 7:29, Christian Miller <realbasic at nc dot rr dot com> 
wrote:

Hello.  In an application I'm writing, I need to filter out non-
alphanumeric characters.  Currently I loop through the text in the
editfield and manually filter A-Z, numbers, etc.  This works great
for English.  Can anyone share with me how I can accomplish the same
thing (automagically?) from within RB for non-English languages?

I recently wrote the following function to test whether a username is valid. I accepts most common characters used in European languages. You could modify it to strip anything that does not match the criteria. I do hope that the extended characters are transferred properly in this email.

Function IsValidUsername(IsValidUsername As String) As Boolean
  Dim IsValid As Boolean = True

  If IsValidUsername.Len < 2 Or IsValidUsername.Len > 20 Then
    IsValid = False
  End if

  If IsValid Then

' Make sure that both value and pattern are in the same 8-bit encoding
    Dim Value, Pattern As String
    Value = ConvertEncoding( IsValidUsername, Encodings.WindowsANSI )
Pattern = ConvertEncoding( "([a-zA-Z0-9À-ÖØ-öø-ÿ_\-\.]+)", Encodings.WindowsANSI )

    IsValid = Value.MatchRegEx( Pattern )

  End if

  Return IsValid

End Function

HTH,

- Rob Laveaux

--------------------------------------------------------
Pluggers Software
Thijssestraat 203
2521 ZG  Den Haag
The Netherlands

Email: rob dot laveaux at pluggers dot nl
Website: http://www.pluggers.nl

--------------------------------------------------------


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>