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 6910089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:46:13+00:00 2026-05-27T08:46:13+00:00

I want the following function to validate a string if it looks like this:

  • 0

I want the following function to validate a string if it looks like this:

  • Any digit (incl. fraction and decimal)
  • optional one of the pieces/bags/boxes synonyms
  • optional one of the male/female synonyms

between each may be a space and the order of the 2 optional parts shouldnt matter (“2 box male” == “2 male box”)

but instead of doing anything useful this function excepts everything that starts with a digit :

Function validAmount(Zelle As Variant)
Set regEx = CreateObject("VBScript.RegExp")
regEx.IgnoreCase = True
regEx.Pattern = "\d\s?(pcs|pieces|piece|pc|stk|bags|bag|box|bx|boxes)?\s?(male|m|female|f)?"
If (regEx.test(Zelle)) Then
    validAmount = True
Else
    validAmount = False
End If End Function

I hope my error isn’t too stupid

edit:
I thought of an additional feature. how could I allow multiple entities of the pattern above seperated by a “,” like “1 box female, 3 bags m, 4pcs male”

ps: both solutions work pretty well but allow something like this “1 male female” or “2 box bag”

edit2:
first of all: I am really thankful for your help! i would have never solved this on my own! and I wanted to click “solved” (cant click “up” cause my reputation is still too low) as soon as everything works as intended. If I should’ve clicked on it earlier I’m sorry. Its my first question here and I’m a little overwhelmed of how fast your answers come 🙂

I think I’m unable to express my wishes 😀 really sorry for that! here is a third try:
only (at least) one of each groups should be allowed. genuine inputs should be:
“# box gender”
“# gender box”
“# box”
“# gender”
“#”
but not:
“# box box” or “# gender gender”

@sln: I think your first looks more like I want it but it allows two instances of the same group even though it looks for me as it shouldnt 🙁 (same for JMax solution)

@JMax: I love your “split” solution! havent even thought of this simple trick 😀 I was so fixed on regex that a havent thought of anything else

  • 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-27T08:46:13+00:00Added an answer on May 27, 2026 at 8:46 am

    Here is a try:

    Function validAmount(Zelle As String)
    Dim sBoxes As String, sGender As String
    Dim arr() As String
    Dim i As Integer
    
    arr = Split(Zelle, ",")
    sBoxes = "pcs|pieces|piece|pc|stk|bags|bag|box|bx|boxes"
    sGender = "male|m|female|f"
    
    validAmount = True
    For i = 0 To UBound(arr)
        Set regEx = CreateObject("VBScript.RegExp")
        regEx.IgnoreCase = True
        regEx.Pattern = "\d\s?(((" & sBoxes & ")?\s?(" & sGender & "))|((" & sGender & ")?\s?(" & sBoxes & ")))?$"
        If (regEx.test(arr(i))) Then
            validAmount = validAmount And True
        Else
            validAmount = validAmount And False
        End If
    Next i
    End Function
    

    And here is a testing procedure:

    Sub unitTest()
    'could use debug.Assert too
    Debug.Print (validAmount("1 box") & " should be True")
    Debug.Print (validAmount("1 boxe male") & " should be False")
    Debug.Print (validAmount("1 pcs female") & " should be True")
    Debug.Print (validAmount("1boxes") & " should be True")
    Debug.Print (validAmount("1 female pcs") & " should be True")
    Debug.Print (validAmount("boxes") & " should be False")
    Debug.Print (validAmount("2 male box") & " should be True")
    Debug.Print (validAmount("1 mytest") & " should be False")
    Debug.Print (validAmount("1 pc box") & " should be False")
    Debug.Print (validAmount("1 box box") & " should be False")
    Debug.Print (validAmount("1 box female, 3 bags m, 4pcs male") & " should be True")
    End Sub
    

    I’ve changed boxes and gender into strings so that you can add both in your pattern (I don’t know any way to check the order without that trick. Does anybody have a better idea?
    I also added a $ to tell Excel this was the end of the string, else any string begining with a digit would pass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ideally I want a function something like the following (this example doesn't compile): void
I want to write the following procedure / function: procedure ShowSysPopup(aFile: string; x, y:
I want to do something like the following in VB.NET, is it possible? Function
i have a variable like the following and i want a function to only
anyone ever worked with the jQuery Validate Plugin. I have like the following function.
I want to define a following function: if(stmtToFinalize) { NSLog(@Finalizing statement stmtToFinalize); if (sqlite3_finalize(stmtToFinalize)
Consider the following function: void f(const char* str); Suppose I want to generate a
I want to define a constant in objective-c. Previously I had the following function:
I want to be able to parse the following times using ParseExact() function: 01:02:03
I want to do the equivalent of the following VB in c# Function([class]) hello

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.