Solved

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

Posted on 2015-01-12
4
166 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: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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with this homework problem. 5 58
Do alert on select 6 26
how to customize the text in the legend in highcharts 3 32
Text color and background in a text box. 2 25
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.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

749 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