![]() |
Regular expression help for Price - Printable Version +- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums) +-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP) +--- Forum: UFT / QTP Regular Expressions (https://www.learnqtp.com/forums/Forum-UFT-QTP-Regular-Expressions) +--- Thread: Regular expression help for Price (/Thread-Regular-expression-help-for-Price) |
Regular expression help for Price - bostonma - 03-01-2011 Hello All, can someone help me guide how I can add regular experession for a Price which is dynamic For ex: Price is 8975 or 8975.99 I would like to add a checkpoint to make sure value is always >8500 How can I do this? RE: Regular expression help for Price - jsknight1969 - 03-01-2011 This should do the trick. Code: (^[1-9]{1}\d{4,9}\.\d{2})|(^[8-9]{1}[5-9]{1}[0-9]{2}\.\d{2}) RE: Regular expression help for Price - manishbhalshankar - 03-01-2011 Hi Bostonma, Roundup the decimal no and then check if it is greater than 8500. RE: Regular expression help for Price - bostonma - 03-02-2011 JSKnight, Can you please explain how the first part works? (^[1-9]{1}\d{4,9}\.\d{2})| RE: Regular expression help for Price - jsknight1969 - 03-02-2011 Sure. It allows any number that starts with 1-9 and has at least 4 other digits before the ".". Basically it is to all 5+ digit numbers that don't start with zero. Any 5+ digit number would be automatically greater than 8500. That had to be allowed since the second part of the script only verified 4 digit numbers between 8500-9999. having to explain this, I noticed an issue. Here is the updated expression. Code: (^[1-9]{1}\d{4,9}\.\d{2})|(^[8]{1}[5-9]{1}[0-9]{2}\.\d{2})|(^[9]{1}\d{3}\.\d{2}) Had to allow 4 digit number than begin with 9 as automatic too. Part 1: allow 5+ digit number that do not start with "0" Part 2: Allow 4 digit number that start with an 8 and has second digit between 5 and 9 Part 3: Allow 4 digit number that starts with 9 RE: Regular expression help for Price - bostonma - 03-09-2011 Sorry for the delay in response. ThankYou for the detailed explanation,definitely helps! Jsknight, I Tried with your code but error is displayed.Is the third part optional because in my case the value is 8500.So I'm wondering if it is looking for .9x? RE: Regular expression help for Price - nanthini222 - 03-09-2011 To make the decimal point optional, (^[1-9]{1}\d{4,9}[\.\d{2}]?)|(^[8]{1}[5-9]{1}[0-9]{2}[\.\d{2}]?)|(^[9]{1}\d{3}[\.\d{2}]?), So it will work for 8585 as well as 8585.99 also Thanks Nanthini RE: Regular expression help for Price - bostonma - 03-11-2011 Thanks much Nanthini. It still failed and I noticed we have a dollar sign,comma and period at the end as well within Price.My bad I did not mention this before. Ex: $8,599.97. Can you be kind enough on how to accommodate these as well?please? Again the period at the end should be optional as well. RE: Regular expression help for Price - jsknight1969 - 03-16-2011 Hopefully this will do it Code: (^[\$]?[\d]{1,3}[,]?[\d]{3}[,]?\d{3}(\.\d{2})?$)|(^[\$]?[1-9]{1}[0-9]{1,2}[,]?\d{3}(\.\d{2})?$)|(^[\$]?[8]{1}[,]?[5-9]{1}[0-9]{2}(\.\d{2})?$)|(^[\$]?[9]{1}[,]?\d{3}(\.\d{2})?$) This should allow anything > 8500 to 999,999,999.99. If you need a larger number than that it will have to be modified. it should also allow "$", "," and "." as optional, however if there is a decimal it must have 2 digits after. |