www.webdeveloper.com
Results 1 to 10 of 10

Thread: Best way to check for multiple characters in a string

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    278

    Best way to check for multiple characters in a string

    I have pages that print Code 39 bar codes; however, I do not have development in place to dissalow the entry of the invalid characters that Code 39 requires. For this discussion, you dont' really need to knwo what Code 39 is, just the list of invalid characters.

    So, upon data entry, I would like to check the string to ensure the following special characters are NOT present in the string, if they are, then I'll alert them or do something:

    !
    @
    #
    ^
    &
    *
    (
    )
    _
    =
    {
    }
    [
    ]
    \
    |
    :
    ;


    <
    >
    ,
    ?

    Because there are so many characters to choose from, I am not certain the best code for this. What do you all suggest would be the best route to take?

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,773

  3. #3
    Join Date
    Aug 2005
    Posts
    278
    Close, but not quite there, I'll describe a bit more.

    They will be entereing in a piece of data, 9/10 they will be pasting it in. So, they may enter in ABC123^4, or ABC1234

    Currently, both are tagged as "Bad Characters" prompt from the above code, when only the first should be.

  4. #4
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,773
    I had the logic a little wrong. The regular express tests to make sure those characters are not there. Revised code is below:
    Code:
    var invalidChars = /[!@#^\&\*\(\)_=\{\}\[\]\\|:;<>,\?]/;
    
    if (str.match(invalidChars)) {
      alert("Bad characters!");
    }
    else {
      alert("Good characters");
    }
    The "^" after the opening "[" causes the character class in the regular expression to be inverted, meaning "match any character that is not a, b, c or d". I changed "[^" to simply "[". That should be all you need.

  5. #5
    Join Date
    Aug 2005
    Posts
    278
    So far so good, thanks a bunch!

  6. #6
    Join Date
    Jan 2013
    Posts
    1
    Code 39 (also known as "USS Code 39", "Code 3/9", "Code 3 of 9", "USD-3", "Barcode 3 of 9", "Type 39") is a linear barcode symbology that can encode upper-case alphanumeric A-Z and 0-9 and some special characters, with lower-case a-z added for Code 39 Extension.
    Sorry, i have no ideas , but you can try to generate barcode in asp.net, including code 39 and other linear barcodes or 2D barcodes.

  7. #7
    Join Date
    Aug 2013
    Posts
    30
    Quote Originally Posted by Thomassunshine View Post
    Code 39 (also known as "USS Code 39", "Code 3/9", "Code 3 of 9", "USD-3", "Barcode 3 of 9", "Type 39") is a linear barcode symbology that can encode upper-case alphanumeric A-Z and 0-9 and some special characters, with lower-case a-z added for Code 39 Extension.
    Sorry, i have no ideas , but you can try to generate barcode in asp.net, including code 39 and other linear barcodes or 2D barcodes.
    does it have a free trial version?

  8. #8
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,348
    The full set of codes is here : http://www.barcodesymbols.com/code39.htm
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  9. #9
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,348
    Code39 are numbers and letters, therefor you only need to test if an input is valid by way of only allowing actual letters or numbers.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  10. #10
    Join Date
    Jun 2014
    Posts
    1
    i heard if you use professional code 39 barcode generator to create code 39 barcode or other barcode types, it will automatically get the check digit and other characters for you, no need to choose from



    java barcode generator with check character

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles