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?
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.
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.
Bookmarks