0

I have the following code that works well for validating length...

DO {
    $NewID = Read-Host -Prompt " NEW ID NAME of object (8-15 chars)   "
} UNTIL ($NewID.Length -gt 7 -and $WS_NewName.Length -lt 16)

How can I include code that ensures input contains either an ALPHA or ALPHANUMERIC string, but NOT a purely NUMERIC one?

1 Answer 1

1

This can be easily doable using regular expressions like that:

($NewID -match '^[A-z0-9]*$') -and ($NewID -notmatch '^[0-9]*$')

Short explanation: first expression looks for alpha/alphanumeric string and the second discards purely numeric entries.

By the way, in your example you use $NewID and then $WS_NewName in Until expression, that might be confusing (however, I assume you just forgot to change it while pasting here)

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, you're right about the variable, @robdy. I overlooked that, sorry. And thanks for the concise explanation to the answer you provided. Made me understand the use and structure or regex better. =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.