Regex Expression for string which should contain only limited type of special characters

How can i check if my string contains Special Characters other than the following special characters.
curly brackets ( )
Square Brackets
Apsotrophe ’
slash /

My String should return false if any special charaters are present other than the above(alphanumeric is accepted)

Can someone please help.

Hi @JITU99

You can use the following pattern for the same:

^[a-zA-Z0-9]*$

image

Hope this helps,
Best Regards.

Hi @arjunshenoy

My string should not contain special charaters other than mentioned here brackets (),square brackets ,slash / , apstrophe ’

@JITU99

As you mentioned, the pattern holds good for all your requirements:

image

Best Regards.

Hi,

Can you try the following expression?

not System.Text.RegularExpressions.Regex.IsMatch(yourString,"[^A-Za-z0-9 ()\[\]'/]")

This allows to include whitespace.If you also need to check whotespace, can you try the following?

not System.Text.RegularExpressions.Regex.IsMatch(yourString,"[^A-Za-z0-9()\[\]'/]")

Regards,

I believe still my question is not clear to you. @arjunshenoy

My striong should contain special cahraters ( , ) , [ , ] , \ , ’ (apostrophe)

@JITU99

I think now it’s clear. Can you please try this pattern:

^[a-zA-Z0-9()\[\]/\\']*$

image

Best Regards.

1 Like

Thanks Again :slight_smile: @Yoichi

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.