Solved

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

Posted on 2015-01-12
4
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Michael Fowler
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:
Michael Fowler 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

627 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