473,401 Members | 2,139 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,401 software developers and data experts.

how to express numeric value in regular expression

hi, now i am doing shopping online page for admin.Admin can upload new items in the web page, but the price of the item should be numeric and it can have decimal place, say the price is 69.99.i don;t know how to write this regular expression in javascript to do my validation. any one can help me? it is urgent as my project deadline is very near. thanks in advance.
Jul 22 '07 #1
1 1985
pbmods
5,821 Expert 4TB
Heya, Kang.

Regular expressions are very good at *describing* strings.

So how do you describe a currency amount?

Well, you have some kind of currency symbol, depending on the currency.
Then you have a bunch of numbers. There might be commas or spaces between sets of three numbers.
Then you have a decimal of some kind. Maybe a dot, or maybe a comma, depending, again, on the currency.
Next, you have (traditionally) two numbers, though this depends on the currency.
Finally, some currencies have a suffix of some kind.

So we'd be looking at something like this for USD:
/\$\d{1,2}(,?\d{3})*\.\d{2}/

Now, you probably don't want to get that intricate, so this will probably suffice:
/\d*\.\d{2}/

Which is any number of numbers (or no numbers at all), then a decimal, and then finally two numbers.

You could modify the regular expression if you wanted to make the 'cents' portion optional:
/\d+(\.\d{2})?/ or /\d*(\.\d{2})?/

The difference between the two is that the first one requires at least one number before the decimal (so '2', '2.67' and '0.67' would be valid, but '.67' would not).

The second one makes the leading number optional (so that '.67' would also be valid, but so would '').

Have fun.
Jul 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: amazononthemoon | last post by:
I have not been able to find any examples of the type of validation I need. I have numeric fields on a web page that I only want them to enter numbers with two decimal places. I would like to...
9
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
6
by: Peter Afonin | last post by:
Hello, Should be a pretty simple question: I need to validate a string. It must be numeric and contain exactly 12 characters. I know how to do it in code, but I'd like to use a validation...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
1
by: David | last post by:
I have rows of 8 numerical values in a text file that I have to parse. Each value must occupy 10 spaces and can be either a decimal or an integer. // these are valid - each fit in a 10 character...
5
by: Bosconian | last post by:
I need a comma delimited regular expression pattern with the followng restrictions: no leading and trailing white space no trailing comma double quoted numeric/alpha pairs each pair on a...
8
by: Mohammad Omer | last post by:
Hi, i want to use regular expression in my project for validation of email. How i can use Regular Expression in VC?? i am using vs2k5 IDE. i seen boost api for regular expression, is it any...
14
by: nishit.gupta | last post by:
Is their any single fuction available in C++ that can determine that a string contains a numeric value. The value cabn be in hex, int, float. i.e. "1256" , "123.566" , "0xffff" , It can also...
8
by: .Net Sports | last post by:
I am checking for text input on a form validation in javascript that required at least one numeric character along with any number of alpha characters for a given input text box. The below is a var...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.