Solved

How do I set up an input (text pattern) for a dollar field

Posted on 2015-01-12
4
160 Views
Last Modified: 2015-02-02
I have a page where I'm getting data from a previous page.  The field is a monthly rental and therefor is #####.##.  The data being passed is "250.00".  I originally had the field as a numeric but that displays "250".  I've tried several different "patterns" that i googled but they didn't work as advertised.

The code that I'm currently running is:

echo '<input type="number" pattern = "0.00-99999.99 {8}" title = "Enter a dollar amount without commas" name="$PSF" size = "8" min = "0.00" max = "99999.99" value="';
echo $work;
echo '" maxlenghth="8" step = "0.01">';

The source code in the browser reads as:

<input type="number" pattern = "0.00-99999.99 {8}" title = "Enter a dollar amount without commas" name="$PSF" size = "8" min = "0.00" max = "99999.99" value="250.00" maxlenghth="8" step = "0.01">

Thanks for the help
Glenn
0
Comment
Question by:breeze351
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Michael74
ID: 40545445
Try using type text with a regex pattern

input type="text" pattern="^\d*(\.\d{2}$)?"

Here are some examples of dealing with this problem.
http://jsfiddle.net/NfMQ7/178/
0
 

Author Comment

by:breeze351
ID: 40554265
That worked.  But how do I let the user add commas to the field?  Is there a site that I can learn how the "pattern" works?
Glenn
0
 
LVL 23

Accepted Solution

by:
Michael74 earned 500 total points
ID: 40556588
The pattern in this case is a regular expression or regex and there are lots a good sites with tutorials on this subject eg http://regexone.com/

Here is a regex that allows for currency

^([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(\.[0-9][0-9])?$

Open in new window

http://regexlib.com/Search.aspx?k=currency
0
 

Author Closing Comment

by:breeze351
ID: 40584731
Got it.
Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question