LiveG Posted April 19, 2022 Posted April 19, 2022 (edited) Hello I am trying to insert a Regular Expression in a text filed that will check the value inserted by user and will validate the following: Only numbers allowed only 1 dot allowed minimum value is 1.4 Can you please help me with the expression? Many thanks 🙏 Edited April 19, 2022 by livegames.co.il
IPCommerceFan Posted April 19, 2022 Posted April 19, 2022 Glad you figured it out! I'm going to post this here anyway, in case someone stumbles on this thread while searching for similar: ^([1-9]\.[4-9]{1}|[2-9]{0,9}\.[0-9]{1}|[0-9]{2,9}\.[0-9]{1})$ https://regex101.com/r/iqeDII/3
LiveG Posted April 19, 2022 Author Posted April 19, 2022 (edited) 8 minutes ago, IPCommerceFan said: Glad you figured it out! I'm going to post this here anyway, in case someone stumbles on this thread while searching for similar: ^([1-9]\.[4-9]{1}|[2-9]{0,9}\.[0-9]{1}|[0-9]{2,9}\.[0-9]{1})$ https://regex101.com/r/iqeDII/3 Thank you, @IPCommerceFan this is what I have done - i thought i figure it out 😌 /^([1-9].?[4-9]|[2-9](.?[0-9])?)$/ But actually, I am struggling to do the minimum of 1.40; because now its accept minimum of 1.4 but reject 1.40 if you can help me, I would appreciate it. Edited April 19, 2022 by livegames.co.il
IPCommerceFan Posted April 19, 2022 Posted April 19, 2022 (edited) Updated! https://regex101.com/r/iqeDII/6 ^([1-9]\.([4-9]{1}|[4-9]{1}[0-9])|[2-9]{0,9}\.[0-9]{1}|[0-9]{2,9}\.[0-9]{1,2}|[2-9]{0,9})$ My understanding was that you only wanted to use 1 decimal place (only 1 dot allowed), which is why the original pattern didn't account for 1.40. How many decimal places should be accounted for? Edited April 19, 2022 by IPCommerceFan
LiveG Posted April 19, 2022 Author Posted April 19, 2022 Yes, sorry for misleading you. 2 decimal max - minimum 1.40 so every decimal number above should work...with the example you sent 1.45 doesn't work i am afraid
IPCommerceFan Posted April 19, 2022 Posted April 19, 2022 Made an edit, try this: ^(([1-9]\.([4-9]{1}|[4-9]{1}[0-9]))|[2-9]{0,9}\.[0-9]{1}|[0-9]{2,9}\.[0-9]{1,2}|[2-9]{0,9})$
LiveG Posted April 19, 2022 Author Posted April 19, 2022 (edited) 6 minutes ago, IPCommerceFan said: Made an edit, try this: ^(([1-9]\.([4-9]{1}|[4-9]{1}[0-9]))|[2-9]{0,9}\.[0-9]{1}|[0-9]{2,9}\.[0-9]{1,2}|[2-9]{0,9})$ I am sorry i am afraid its not working. I am checking it here https://regex101.com/ Edited April 19, 2022 by livegames.co.il
Solution IPCommerceFan Posted April 19, 2022 Solution Posted April 19, 2022 Ah yes, try this: ^(([1-9]\.([4-9]{1}|[4-9]{1}[0-9]))|[2-9]{0,9}\.[0-9]{1,2}|[0-9]{2,9}\.[0-9]{1,2}|[2-9]{0,9})$ LiveG 1
LiveG Posted April 19, 2022 Author Posted April 19, 2022 Its works perfect!! @IPCommerceFan Thanks a lot for your time and effort! It is Well appreciated. IPCommerceFan 1
Recommended Posts