Pete
asked on
regex expression
Hello, I want to only allow an input if it satisfies the following, can you please advise on a suitable regex expression.
Less than or equal to 8 characters
Does not have a preceding or following empty space
Is only made up of a-z, A-Z, 0-9 or a hyphen -
clear, rather than concise preferred...
Thanks
Less than or equal to 8 characters
Does not have a preceding or following empty space
Is only made up of a-z, A-Z, 0-9 or a hyphen -
clear, rather than concise preferred...
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks I would just stop the script with an error until the leading blank spaces could be sorted.
oBda doesnt mention the blank space, is that dealt with the expression anyway?
'\A[a-zA-Z0-9-]{1,8}\Z'
oBda doesnt mention the blank space, is that dealt with the expression anyway?
'\A[a-zA-Z0-9-]{1,8}\Z'
Yes, since the space isn't in the set of allowed characters.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is the /A /Z syntax compatible with powershell, rather than ^ and $?
Thanks
Thanks
ASKER
how about allowing white space anywhere other than at the start or beginning?
Thanks
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You might enjoy this article that shows how we go about building regular expressions, and testing them for success:
https://www.experts-exchange.com/articles/7830/A-Quick-Tour-of-Test-Driven-Development.html