Can you please provide me with a regular expression that would
- Allow only alphanumeric
- Have definitely only one hyphen in the entire string
- Hyphen or spaces not allowed at the front and back of the string
- no consecutive space or hyphens allowed.
- hypen and one space can be present near each other
Valid – “123-Abc test1″,”test- m e”,”abc slkh-hsds”
Invalid – ” abc “, ” -hsdj sdsd hjds- “
Thanks for helping me out on the same. Your help is much appreciated
See demo here.
EDIT:
If there can’t be a space on both sides of the hyphen, then there needs to be a little more:
Alternatively, if negative lookbehind assertions aren’t supported (e.g. in JavaScript), then an equivalent regex: