Regex help ' and - characters

Hi,

I am trying to create a regex match that detects if illegal characters in a string.

Currently I have “[1]+$” but I would like to add - and ’ as characters to be allowed into it.

Thanks for your help.


  1. A-Za-z0-9 ↩︎

Hi,

We cannot see the above pattern properly due to it’s this forum’s meta character.
For now, Can you try as the following?

System.Text.RegularExpressions.Regex.IsMatch(yourString,"[-'+$]")

If the above doesn’t work for you, please share your current pattern as image or preformated text ( using the above </> menu)

Regards,

2 Likes

Hi @LeThomp

Further to @Yoichi’s post, if you don’t know all the illegal characters you can validate your text by inserting the ‘allowed’ characters.

Like this:
System.Text.RegularExpressions.Regex.IsMatch(yourString,“[^a-zA-Z0-9 ]”)

This will match on anything that is not a:

  • Number (“0-9”)
  • Letter (“A-Z” or “a-z”)
  • Space (" ")

Hopefully this helps you.

Cheers

Steve

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