It's all about the answers!

Ask a question

Regular expression to validate a string


Rajat Singh (59833545) | asked May 06 '16, 3:42 a.m.
Hi Team

I am looking for a regular expression to match 3 pre-defined values under a simple string attribute of type text.
The requirement is to enter either of the three values:
Required, Not Required, Done

I have written the below expression to validate:
(^|\s)Required|Not Required|Done(\s|$)

This works only for the first value.
If I enter the same value or different value on the new line; it gives me an error.

Please let me know what am I missing here.

Thanks
Rajat

Comments
Rajat Singh commented May 06 '16, 6:03 a.m.

Managed to get the following expression working


((Done)\n|(Required)\n|(Not Required)\n){0,3}

However it is case sensitive even if we remove the check mark from the validator.

Any suggestions??


Donald Nong commented May 09 '16, 3:07 a.m.

Use the "i" switch.


Rajat Singh commented May 09 '16, 7:46 a.m.

 Thanks but it does not work when using \n.

I have entered regular expression as:
((Required)\n|(Done)\n|(NotRequired)\n){0,7}

Could you give me an example as to how can 'i' switch work on this.

Regards
Rajat

Be the first one to answer this question!


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.