• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Having Query with Regex . I dont want the decimals to be displayed

 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Regex line written. Its like this,


Which is restricting all the decimal values , but I also want to restrict the decimal point too. For example if i type 3.


It should restrict that too. Where Am i going wrong please suggest
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

That code isn't Java. I almost moved this topic to the JS forum, but then realized that there are some other languages that looks similar. Please confirm the language so we can move this topic.

Henry
 
Henry Wong
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vishal Hegde wrote:I have a Regex line written. Its like this,


Which is restricting all the decimal values , but I also want to restrict the decimal point too. For example if i type 3.


It should restrict that too. Where Am i going wrong please suggest




Also, please explain what you mean by "restricting" -- can't tell from the context whether you mean it to match, or not match.

Henry
 
Sheriff
Posts: 22702
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right now your code allows Strings like 1.2.3. Is that what you want?
If you change the final + (right before the $) into a ?, it makes the "dot followed by one or more digits" optional, requiring either no decimals at all, or one decimal group.
 
Vishal Hegde
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose i have a number 3.5686 then there is a condition written by me that decimal is not allowed, but suppose i type on 3. then it is not going to that if loop where this error msg is written.I want a regex which doesnot allow decimals too.


It is in JS
 
Henry Wong
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vishal Hegde wrote:Suppose i have a number 3.5686 then there is a condition written by me that decimal is not allowed, but suppose i type on 3. then it is not going to that if loop where this error msg is written.I want a regex which doesnot allow decimals too.


It is in JS



As already mentioned, a "3" by itself will not work -- as your regex requires that it is followed by at least one or more sets of decimal points followed by numbers. So, "3.5686" will work, "3.55.67" will work, and even "3.55.78.34.56" will work, but "3" or "3." will not work.


And probably no reason to move to the JS forum, as this topic is more regex related.... However, next time, it may be better to post it there instead.

Henry
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic