How to check if a string contains a number in powershell
Asked Answered
P

1

5

How do I check if a string contains any numeric value.

Ex: paul123

The above example contains numeric value so I should get the output as true.

Penile answered 7/7, 2017 at 15:7 Comment(0)
B
6

Use a regular expression match:

'paul123' -match '\d'

\d matches a digit (0-9), so the expression will evaluate to true if the string contains at least one digit.

Bree answered 7/7, 2017 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.