I’ve trying to get a regular expression to work with no luck. I’ve been able to to limit the expression to an alphanumeric number with 10 digits:
(^[a-zA-Z0-9]{10}+$)
however i am also trying to get it allow the $ character with only 1 match in any position.
it should come up as true for something like, pQp3b8ar$8 or k7DdRoB$5W.
Three general notes:
^[a-zA-Z0-9$]{10}${10}+does not make much sense, drop the plus (there’s no need for a possessive quantifier on a fixed count)To allow a dollar sign only once, you can use an extended version of the above:
^(?=[^$]*\$[^$]*$)[a-zA-Z0-9$]{10}$The
(?=[^$]*\$[^$]*$)is a look-ahead that readsIt allows any characters on the string but the dollar only once.
Another variant would be to use two look-aheads, like this:
^(?=[^$]*\$[^$]*$)(?=[a-zA-Z0-9$]{10}$).*Here you can use the
.*to match the remainder of the string since the two conditions are checked by the look-aheads. This approach is useful for password complexity checks, for example.