PDA

View Full Version : Regular expression in textfield.



drilli
11 Sep 2012, 6:48 AM
I have a text field with this maskRe and ERgular Expression:

maskRe: /^([0-9 \/]*)$/
regex: /^[0-9]*([0-9]*\/?[0-9]*)[0-9]$/

I need to allow user write a string in this form: number/number.
It allows only one '/' and starts with number and ends with number

Can you help me because the regEx above it`s not working as it should

scottmartin
11 Sep 2012, 7:30 AM
Here are a few online builders:
http://www.rubular.com/
http://refiddle.com/

Scott.

Zdeno
11 Sep 2012, 12:51 PM
I think i already wrote same regular to someone else:


^(\d)*\/(\d)*$

\d is same like [0-9]

drilli
11 Sep 2012, 11:21 PM
I think i already wrote same regular to someone else:


^(\d)*\/(\d)*$

\d is same like [0-9]


I tried it but it doesn`t work. I need to be just number or number / number

Zdeno
12 Sep 2012, 12:07 AM
^(\d)*\/?(\d)*$

drilli
12 Sep 2012, 12:18 AM
Thank You indeed for helping. I tried it but it didn`t work also. I modified to this : /^(\d)*(\/?(\d)*)(\d)$/. It works already exept that it allows to write something like this: /number (e.g /1) and it shouldn`t allow that. It doesn`t allow 1/ or / or // or 1// or //1. but it allows /1.

Zdeno
12 Sep 2012, 12:48 AM
Try
^(\d+\/?\d+)$|^\d+$

drilli
12 Sep 2012, 1:34 AM
Try
^(\d+\/?\d+)$|^\d+$

Thank you. It works now. I still don`t know what does all these characters mean but the important thing is that it`s working.

Zdeno
12 Sep 2012, 6:56 AM
http://www.w3schools.com/jsref/jsref_obj_regexp.asp
http://www.regular-expressions.info/ (http://www.regular-expressions.info/)

scottmartin
12 Sep 2012, 7:12 AM
ah ... PowerGREP/regexbuddy are good apps

Still have them on my XP VM .. wish they where multi-OS.

Scott.