Accepting only 2 special characters in a string

Hi, I have to accept a string which can have (not mandatory) only two special characters which are ’ & -

For example:

  1. Prakash Kaur(this string should be accepted)
  2. Prakash’s Kaur (this string should also be accepted
  3. Prakash-Kaur (this string should also be accepted)
  4. Prakash / Kaur (this string should be rejected)

Hi!

You can use the activity Is Match which checks if a regular expression finds a match in a given string.

For your problem, you could try with this regex: /^[a-zA-Z\s'&\-]*$/ which matches with any string that has only letters spaces (\s) or the special characters you mentioned ( ’ & - )

2 Likes

Thank you so much for this solution. I will try this on Monday morning and will get back sharing the results.

1 Like

Were you able to make it work?

Unfortunately it isn’t working

[a-zA-Z, ,\',\-]*