G
Guest
C#
I am writing a function that allows the user to enter fractions as answers
(i.e. how many asprin tablets for a dosage?).
I have the first half of the Regex figured out but don't know how to do the
second half. In the snippet "1-2 1/2". I can figure out the part before the
dash but not after. The second part is optional for the user. If it is there
it must be complete
Any hints?
"^([0-9]+|[0-9]+\/[1-9]+|[0-9]+ [0-9]+\/[1-9]+)$"
t0 = "1" - pass
t1 = "1-1" - pass
t2 = "1/2" - pass
t3 = "1 1/2" - pass
t4 = "1 1/2-2" - pass
t5 = "1 1/2-2 1/2" -pass
f1 = "1-" - fail
f2 = "1 1/2-" - fail
f3 = "1/2 1/2" - fail
f4 = "1/2-1/2-" - fail
f5 = "2-1" - fail ??
I am writing a function that allows the user to enter fractions as answers
(i.e. how many asprin tablets for a dosage?).
I have the first half of the Regex figured out but don't know how to do the
second half. In the snippet "1-2 1/2". I can figure out the part before the
dash but not after. The second part is optional for the user. If it is there
it must be complete
Any hints?
"^([0-9]+|[0-9]+\/[1-9]+|[0-9]+ [0-9]+\/[1-9]+)$"
t0 = "1" - pass
t1 = "1-1" - pass
t2 = "1/2" - pass
t3 = "1 1/2" - pass
t4 = "1 1/2-2" - pass
t5 = "1 1/2-2 1/2" -pass
f1 = "1-" - fail
f2 = "1 1/2-" - fail
f3 = "1/2 1/2" - fail
f4 = "1/2-1/2-" - fail
f5 = "2-1" - fail ??