Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6158531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:58:20+00:00 2026-05-23T20:58:20+00:00

I need to validate a string, which might contain alphanumeric as well as special

  • 0

I need to validate a string, which might contain alphanumeric as well as special character, where as I have to pass the one which has only Alpha chars (no numbers or any other special characters are allowed)

In a current method I use ASCII numbers to evaluate each character if its alpha or not. Is there any other efficient way to discover the presence of special characters or numbers in the string? Like can’t we use Like or something to check once than going character by character?

For y = 2 To Len(sString)
    If Not ((Asc(Mid$((sString,y,1))>64 AND Asc(Mid$((sString,y,1))<91) OR _
    (Asc(Mid$((sString,y,1))>96 AND Asc(Mid$((sString,y,1))<123)) Then
        //Display an error msg
        Exit For
    End If
Next y
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:58:20+00:00Added an answer on May 23, 2026 at 8:58 pm

    You can use regular expressions in VB6. You have to add a reference to the “Microsoft VBScript Regular Expressions 5.5” library to your project. You can then use the following:

    Dim rex As RegExp
    Set rex = New RegExp
    rex.Pattern = "[^a-zA-Z]"
    If rex.Test(s) Then
        ' Display error message
    End If
    

    When I originally answered this question, it was tagged as VB.NET; for future reference, my original .Net-based answer is retained below

    As you thought, this can be done with regular expressions (don’t forget Imports System.Text.RegularExpressions:

    If Regex.IsMatch(s, "[^a-zA-Z]") Then
        ' Display error msg
    End If
    

    Also, the original code reads like VB6 code, not VB.NET. Here is a much more readable way to write the original non-regex code:

    For Each ch As Char In someString
        If Not (ch >= "a"c AndAlso ch <= "z"c OrElse ch >= "A"c AndAlso ch <= "Z"c) Then
            ' Display error msg
            Exit For
        End If
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a calculation application which I need to validate the fields to check
I have a text field which I need to validate using a regex. My
I need to validate following string using Regular Expressions. These are the constraints which
I need to validate an XML string (and not a file) against a DTD
I need to be able to validate a string against a list of the
I need a regex or a function in PHP that will validate a string
I need to validate a certain property to one of my classes. When I
I’m trying to validate a string which contains numbers where each four numbers are
I've got a string which is pipe '|' delimited. I need a regex to
I need to validate a textBox entry which contains time. Time should be in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.