Regular expression for no white space at start or end, but allow white space in middle, but also allow only one char inputs:
The closest I have got is : ^([^\s])([\sa-zA-Z0-9_\-]*)([^\s])$
The problem with this is that it will only pass if the input is three or more chars, I need it to accept a single char and pass. EG:
The following should pass (using ” for easy of reading, not required in string)
"A"
"A B"
"Hello There"
The following should fail
" A"
"A "
" A "
" test"
also needs to only allow A-Z a-z 0-9 – _ though out, with addition of spaces in middle section but not at start or end
Any ideas?
Thanks
Non-spaces, optionally followed by multiple groups of spaces then non-spaces:
Edit:
To include the character restrictions, just replace non-space classes with allowable characters:
Also, consider being Unicode friendly and using something like
(assuming your regex interpreter allows it).