Easy String Format Validation?

I'm creating a program that will take a string scanned in from a barcode reader and store it in a database. Depending on the unit scanned, there will be a specific format for that unit's barcode.

Is there any easy way to validate the format of the string?

i.e., I want to see if a string is in the format (021#######) or
(y38###-######).

TIA

--Nips


Comments


  • You can use Regular Expression Validation for this:

    imports System.Text.RegularExpressions

    private sub ValidateExp(strToBeValidated as String)
    dim r as Regex = new Regex("021[0-9a-zA-Z]{7}")
    dim m as Match = r.Match(strToBeValidated)
    if m.Success then
    msgbox ("correct")
    end if
    end Sub

    Similarly for y38###-###### you can use
    new Regex("y38[0-9a-zA-Z]{3}-[0-9a-zA-Z]{6}")

    Here i am assuming that by # you mean any character from a to z OR from A to Z or from digits 0 to 9.

    Hope that helps.













    : I'm creating a program that will take a string scanned in from a barcode reader and store it in a database. Depending on the unit scanned, there will be a specific format for that unit's barcode.
    :
    : Is there any easy way to validate the format of the string?
    :
    : i.e., I want to see if a string is in the format (021#######) or
    : (y38###-######).
    :
    : TIA
    :
    : --Nips
    :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion