1

I already use this regex: "^[0-9a-zA-Z]{6,}$"

it allows: numbers, uppercase letters, lowercase letters. it disallows: whitespaces and special characters or symbols.

But I want to modify it to:

- allow: numbers, and either uppercase letters or lowercase letters.
- disallow: whitespaces and special characters or symbols.

Actually i want to use it as regex for Transaction ID.

Valid examples:

  • TY5TF45TF463CHB7437R (UPPERCASE+NUMBERS)
  • ecrx3yt4cx345748bnc7547 (LOWERCASE+NUMBERS)
  • 745367456475647378563745 (ONLY NUMBERS)
  • hdgfsdgfsdjfgshdgshdgf (ONLY LOWERCASE)
  • DHFGSDHGFSHDGFHSGFHSDFH (ONLY UPPERCASE)

Invalid Examples:

  • sshd434gfhdghHSDGFH324234SDFHSG (UPPERCASE+LOWERCASE+NUMBER)

  • SDASGDASDhghgshdfsh (uppercase+lowercase)

  • dhf hsh-d-f-837_483@^%f#@^#2482 (special characters)

2 Answers2

1

You can use this

^(?:[\da-z]+|[\dA-Z]+)$
  • ^ - Anchor to start of string.
  • [\da-z]+- Matches digit + alphabets (lowercase)
  • | - Alternation
  • [\dA-Z]+- Matches digit + alphabets (Uppercase)
  • $ - End of string.

Demo

Code Maniac
  • 33,907
  • 4
  • 28
  • 50
1

something like /^([0-9a-z]+|[0-9A-Z]+)$/m should do it.

SolidSnake
  • 20,635
  • 18
  • 68
  • 89