• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Vishal Hegde
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • 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
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!