I need to validate building name in the below format (length is 1-50)
my regex for alphanumeric and specified characters check
/^[a-zA-Z0-9\s\)\(\]\[\._-&]+$/
Its showing invalid expression but when i exclude & it works fine.
/^[a-zA-Z0-9\s\)\(\]\[\._-]+$/
Actual Format
- Building name should use Letters, Numbers, Underscore_, Hyphen-, Period., Square-brackets[], Parentheses() ,Ampersand &
- It should not start and end with any special characters continuously
Valid:
- Empire3 State&Building[A]
- 7Empire.State-Building(A)
- Empire(State)_Building[A]12
Invalid:
- @#$@$@building))
- ().-building2
- $buildingseven[0]&.
i am struggling for 2nd format. how to check for continuous allowed special characters at first and last. Any help is very much appreciated.