mightofnight
asked on
Need some help with an regex
ok for my program i have an discoutn field. The discount can be an amount or a percent.
I wrote these regex
// Figures out if it's it's an valid amount
'^[0-9]*(\.[0-9]{1,2})?$';
// Figures out if it's it's an valid percent
'^[0-9]*(\.[0-9]+)?%$';
// which i turned into this statement....
'(^[0-9]*(\.[0-9]+)?%$)|(^ [0-9]*(\.[ 0-9]{1,2}) ?$)';
here is the output of my test script...
http://mightofnight.com/forum/reg_test.php
here is my script
http://mightofnight.com/forum/reg_test.phps
ok my problem is that after i did that i realzed that i needed a preg_match statement and that for some reason my regular expression doesn't work and i have no information on how a preg_match statement is different from a regex one
As always any ideas, links or help is greatly appreciated..
I wrote these regex
// Figures out if it's it's an valid amount
'^[0-9]*(\.[0-9]{1,2})?$';
// Figures out if it's it's an valid percent
'^[0-9]*(\.[0-9]+)?%$';
// which i turned into this statement....
'(^[0-9]*(\.[0-9]+)?%$)|(^
here is the output of my test script...
http://mightofnight.com/forum/reg_test.php
here is my script
http://mightofnight.com/forum/reg_test.phps
ok my problem is that after i did that i realzed that i needed a preg_match statement and that for some reason my regular expression doesn't work and i have no information on how a preg_match statement is different from a regex one
As always any ideas, links or help is greatly appreciated..
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
'/(^[0-9]*(\\.[0-9]+)?%$)|
ok thanks for both of your comments..
jdpipe i am unable to directly use the statement you setup brecause this regex is going to be used in three different places... javascript form validation, regular form validation and and to determin the data type as needed. Thouhg the example you provided did help me understand some of the syntex that i needed to change.
Diable84 Thanks for the comment. I wasn't really looking for a php.net link seeing as thats always the first place i look. gotta love the quick searching php.net/*name of function or command here that you are looking for*. But you did point me to a spot that i had overlooked.
THanks again guys