Validate a string with a regex -
i need write regular expression handle below constraints:
names can contain letters, numbers, hyphens (-), dollar signs, brackets ([ , ]), , underscores (_). single periods (.) allowed inside of internal name (abc.de), not @ beginning or end of internal name (.abc or def.). spaces , other special characters not listed here not supported.
i wrote this:
(^[^\.])([a-za-z0-9\.\$\[\]\_\-])*[^.] but still can put 1 sign like: ! or @ or %
^(?!\.)([a-za-z0-9\.\$\[\]\_\-])+(?<!\.)$ you need anchors .also [^\.] can accept other ..so lookaheads , lookbehinds advised.
see demo.