Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Error in using validator`s for string validation.

 Hi ,

I created a validator using the regular expression which should allow either

00000000 or 00000000-00 as below
(([0-9]{8})|([0-9]{8}-[0-9]{2});?)+

when test using the test filed it is working fine but the real thing is not working as expected , i mean the attribute which is using this validator is allowing only the 00000000 as the correct value.

Could some please help me in understanding this issue?

Thanks
Surender

0 votes



One answer

Permanent link
I don't have an explanation as to why, but reversing your expression works for me:
(([0-9]{8}-[0-9]{2}|[0-9]{8});?)+

0 votes

Comments

Thanks Brain for your help.


I have one more requirement 

i.e.,  My regular expression should allow the following pattern
00000000 or 00000000-00 seperated by ;

the  expression working very fine for the pattern but it is accepting even without the special character. 

(([0-9]{8}-[0-9]{2}|[0-9]{8});?)+

How can I force to have the special character between two formats?

Thanks
Surender

RegEx questions probably don't belong in this forum and you may get better responses somewhere like stackoverflow.  In any case, this
^([0-9]{8}-[0-9]{2}|[0-9]{8})(;([0-9]{8}-[0-9]{2}|[0-9]{8}))*
works for me.  No guarantees that there aren't more efficient ways to accomplish the same thing.

could you please help me in case i want the validation should be MMM-YYYY format. what should  be the regular expression?

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Dec 03 '14, 6:19 a.m.

Question was seen: 2,826 times

Last updated: Dec 27 '18, 10:59 a.m.

Confirmation Cancel Confirm