473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Reg exp not working...

Kim
Hello,

I want valid input to be 1 to 9 digits followed by an optional decimal
point, followed by an optional 1 to 4 digits. I think this should
work:

re = /\d{1,9}\.?\d{1,4}/

The problem I am having is that it is not restricting the number of
digits to the right and left of the decimal point. So my "range" parts
({1,9} and {1,4}) are probably wrong in some way but I cannot figure
out how... I have researched the syntax and this seems to make sense to
me. Please help!

Thanks,

Kim

Oct 21 '05 #1
4 943
On 21/10/2005 16:26, Kim wrote:

[snip]
re = /\d{1,9}\.?\d{1,4}/

The problem I am having is that it is not restricting the number of
digits to the right and left of the decimal point.


Only the decimal point is optional, not the decimal part (which is the
intent, I assume). It also only needs to match a substring. Additional
characters, including non-numeric ones, can appear before and after the
matched pattern.

/^\d{1,9}(\.\d{1,4})?$/

The ^ and $ assertions ensure that the pattern matches characters at the
start and end of the string, respectively. In other words, the entire
string must match the pattern.

[snip]

Hope that helps,
Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Oct 21 '05 #2
Kim
I realized I was missing the second ? after I posted. Thanks so
much!!! That works perfectly! :-)

Oct 21 '05 #3
Kim wrote on 21 okt 2005 in comp.lang.javascript:
I want valid input to be 1 to 9 digits followed by an optional decimal
point, followed by an optional 1 to 4 digits. I think this should
work:

re = /\d{1,9}\.?\d{1,4}/

result = /\d{1,9}\.?\d{1,4}/.test(myString)

this would accept 1-9 digits + a optional . + 1 to 4 digits

anyware in a long string.

"qwerty1234567891234qwerty" would be accepted.
The problem I am having is that it is not restricting the number of
digits to the right and left of the decimal point. So my "range" parts
({1,9} and {1,4}) are probably wrong in some way but I cannot figure
out how... I have researched the syntax and this seems to make sense to
me. Please help!


Try:

function result(x){
return /^\d{1,9}(\.\d{1,4})?$/.test(x)
}

alert(result('12')) //true
alert(result('qwerty12')) //false
alert(result('12.23')) //true
alert(result('12.')) //false
alert(result('.23')) //false
alert(result('0.23')) //true
alert(result('000000000.2300')) //true ????

This what you want?

================

or without accepting starting (except in 0.23) and final zeros:

function result(x){
return /^(([1-9]\d{0,8})|0)(\.\d{0,3}[1-9])?$/.test(x)
}

alert(result('12')) //true
alert(result('qwerty12')) //false
alert(result('12.23')) //true
alert(result('12.')) //false
alert(result('.23')) //false
alert(result('0.23')) //true
alert(result('000000000.2300')) //false !!!!
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 21 '05 #4
Kim
I am using: /^\d{1,9}(\.\d{1,4})?$/

Thank you for you quick and effective responses!

:-)

Kim

Oct 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
4
by: qbproger | last post by:
I'm developing a plugin for some software. The previous version of the software didn't require a start in directory to be set. This allowed me to leave the working directory to the default in the...
3
by: Jason Huang | last post by:
Hi, In our C# Windows Form application, we are using the SQL Server 2000 as the database server. The Database table MyTable has a field RegistrationDate which represents the Date a client comes...
0
by: WORKING IN FAITH | last post by:
three years I LOVE You Monica More options 1 message - Collapse all WORKING IN FAITH View profile More options Nov 13, 11:29 am three years I LOVE You Monica
3
by: lds | last post by:
On our server we have both applications that have been migrated to use v2.0 of the framework as well as apps that have not yet been migrated and still use 1.1. When I tried to deploy my v2.0 app...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.